当前位置: 首页>>代码示例>>Python>>正文


Python EveApiManager.check_if_api_server_online方法代码示例

本文整理汇总了Python中services.managers.eve_api_manager.EveApiManager.check_if_api_server_online方法的典型用法代码示例。如果您正苦于以下问题:Python EveApiManager.check_if_api_server_online方法的具体用法?Python EveApiManager.check_if_api_server_online怎么用?Python EveApiManager.check_if_api_server_online使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在services.managers.eve_api_manager.EveApiManager的用法示例。


在下文中一共展示了EveApiManager.check_if_api_server_online方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():
    users = User.objects.all()
    logger.debug("Running api refresh on %s users." % len(users))
    for user in users:
        # Check if the api server is online
        logger.debug("Running api refresh for user %s" % user)
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            logger.debug("User %s has api key pairs %s" % (user, api_key_pairs))
            if api_key_pairs:
                authserviceinfo, c = AuthServicesInfo.objects.get_or_create(user=user)
                logger.debug("User %s has api keys. Proceeding to refresh." % user)
                for api_key_pair in api_key_pairs:
                    try:
                        refresh_api(api_key_pair)
                    except evelink.api.APIError as e:
                        if int(e.code) >= 500:
                            logger.error("EVE API servers encountered error %s updating %s" % (e.code, api_key_pair))
                        elif int(e.code) == 221:
                            logger.warn("API server hiccup %s while updating %s" % (e.code, api_key_pair))
                        else:
                            logger.info("API key %s failed update with error code %s" % (api_key_pair.api_id, e.code))
                            EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                            EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                            notify(user, "API Key Deleted", message="Your API key ID %s failed validation with code %s. It and its associated characters have been deleted." % (api_key_pair.api_id, e.code), level="danger")
                # Check our main character
                if EveCharacter.objects.filter(character_id=authserviceinfo.main_char_id).exists() is False:
                    logger.info("User %s main character id %s missing model. Clearning main character." % (user, authserviceinfo.main_char_id))
                    authserviceinfo.main_char_id = ''
                    authserviceinfo.save()
                    notify(user, "Main Character Reset", message="Your specified main character no longer has a model.\nThis could be the result of an invalid API\nYour main character ID has been reset.", level="warn")
        set_state(user)
开发者ID:johanko,项目名称:allianceauth,代码行数:34,代码来源:tasks.py

示例2: run_alliance_corp_update

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_alliance_corp_update():
    # I am not proud of this block of code
    if EveApiManager.check_if_api_server_online():
        # Get Corp info
        corp_info = EveApiManager.get_corporation_information(settings.ALLIANCE_ID, settings.ALLIANCE_EXEC_CORP_ID,
                                                              settings.ALLIANCE_EXEC_CORP_VCODE)

        # Dummy alliance info
        if not EveManager.check_if_alliance_exists_by_id(settings.ALLIANCE_ID):
            EveManager.create_alliance_info(settings.ALLIANCE_ID, corp_info['name'], corp_info['ticker'],
                                            settings.ALLIANCE_ID, 1, False)
        else:
            # Update semi fake data no real point
            EveManager.update_alliance_info(settings.ALLIANCE_ID, settings.ALLIANCE_ID,
                                            1, False)

        # Get the fake data we just added / updated
        alliance = EveManager.get_alliance_info_by_id(settings.ALLIANCE_ID)

        # Only one corp add or update
        if not EveManager.check_if_corporation_exists_by_id(corp_info['id']):
            EveManager.create_corporation_info(corp_info['id'], corp_info['name'], corp_info['ticker'],
                                               corp_info['members']['current'], False, alliance)
        else:
            EveManager.update_corporation_info(corp_info['id'], corp_info['members']['current'], alliance,
                                               False)
开发者ID:RZN-FFEvo,项目名称:corpauth,代码行数:28,代码来源:tasks.py

示例3: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():
    if not EveApiManager.check_if_api_server_online():
        logger.warn("Aborted scheduled API key refresh: API server unreachable")
        return

    for u in User.objects.all():
        refresh_user_apis.delay(u)
开发者ID:CokkocZateki,项目名称:allianceauth,代码行数:9,代码来源:tasks.py

示例4: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():

    users = User.objects.all()

    for user in users:
        # Check if the api server is online
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            if api_key_pairs:
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                if settings.DEBUG:
                    print 'Running update on user: ' + user.username
                if authserviceinfo.main_char_id and authserviceinfo.main_char_id != "":
                    for api_key_pair in api_key_pairs:
                        if settings.DEBUG:
                            print 'Running on ' + api_key_pair.api_id + ':' + api_key_pair.api_key
                        if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                            # Update characters
                            characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                               api_key_pair.api_key)
                            EveManager.update_characters_from_list(characters)
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            main_alliance_id = EveManager.get_charater_corporation_id_by_id(
                                authserviceinfo.main_char_id)

                            # NPC corps return as None
                            if main_alliance_id is None or int(main_alliance_id) != int(settings.ALLIANCE_ID):
                                if settings.DEBUG:
                                    print 'Not in Corp'

                                SlackManager.send_director('API ERROR: ' + user.username +
                                                           ' Not in corp.\n\tServices disabled.\n\tAPI removed.')

                                remove_user_all_groups(user)
                                deactivate_services(user)
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                        else:
                            if settings.DEBUG:
                                print 'Bad API Deleting character and api for ' + user.username

                            SlackManager.send_director('API ERROR: Bad API for user ' + user.username +
                                                       '\n\tServices disabled.\n\tAPI removed.')

                            remove_user_all_groups(user)
                            deactivate_services(user)
                            EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                            EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)

                else:
                    if settings.DEBUG:
                        print 'No main_char_id set'
开发者ID:RZN-FFEvo,项目名称:corpauth,代码行数:56,代码来源:tasks.py

示例5: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():
    users = User.objects.all()

    for user in users:
        # Check if the api server is online
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            if api_key_pairs:
                valid_key = False
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                print 'Running update on user: ' + user.username
                if authserviceinfo.main_char_id:
                    if authserviceinfo.main_char_id != "":
                        for api_key_pair in api_key_pairs:
                            print 'Running on ' + api_key_pair.api_id + ':' + api_key_pair.api_key
                            if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                                # Update characters
                                characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                                   api_key_pair.api_key)
                                EveManager.update_characters_from_list(characters)
                                valid_key = True
                            else:
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, api_key_pair.api_key)

                        if valid_key:
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            corp = EveManager.get_corporation_info_by_id(character.corporation_id)
                            main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
                            if main_alliance_id == settings.ALLIANCE_ID:
                                pass
                            elif corp is not None:
                                if corp.is_blue is not True:
                                    deactivate_services(user)
                            else:
                                deactivate_services(user)
                        else:
                            # nuke it
                            deactivate_services(user)
                else:
                    print 'No main_char_id set'
开发者ID:Krienas,项目名称:allianceauth,代码行数:45,代码来源:tasks.py

示例6: run_databaseUpdate

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_databaseUpdate():
    users = User.objects.all()
    for user in users:
        groups = user.groups.all()
        syncgroups = SyncGroupCache.objects.filter(user=user)
        add_to_databases(user, groups, syncgroups)
        remove_from_databases(user, groups, syncgroups)

    # no point if slack isn't enabled
    # this isn't really going to run every minute
    # cache will stop it
    if SlackManager.enabled():
        if EveApiManager.check_if_api_server_online():
            kill_api = EveApiManager.get_corp_kills(settings.ALLIANCE_EXEC_CORP_ID, settings.ALLIANCE_EXEC_CORP_VCODE)
            for kill in kill_api.result:
                if not EveManager.check_corporation_kill(kill):
                    # if sent save to db
                    if SlackManager.send_kill(kill):
                        EveManager.create_corporation_kill(kill)
开发者ID:RZN-FFEvo,项目名称:corpauth,代码行数:21,代码来源:tasks.py

示例7: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():
    users = User.objects.all()
    logger.debug("Running api refresh on %s users." % len(users))
    for user in users:
        # Check if the api server is online
        logger.debug("Running api refresh for user %s" % user)
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            logger.debug("User %s has api key pairs %s" % (user, api_key_pairs))
            if api_key_pairs:
                authserviceinfo, c = AuthServicesInfo.objects.get_or_create(user=user)
                logger.debug("User %s has api keys. Proceeding to refresh." % user)
                for api_key_pair in api_key_pairs:
                    refresh_api(api_key_pair)
                # Check our main character
                if EveCharacter.objects.filter(character_id=authserviceinfo.main_char_id).exists() is False:
                    logger.info("User %s main character id %s missing model. Clearning main character." % (user, authserviceinfo.main_char_id))
                    authserviceinfo.main_char_id = ''
                    authserviceinfo.save()
        set_state(user)
开发者ID:Cafune,项目名称:allianceauth,代码行数:22,代码来源:tasks.py

示例8: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():
    users = User.objects.all()
    logger.debug("Running api refresh on %s users." % len(users))
    for user in users:
        # Check if the api server is online
        logger.debug("Running api refresh for user %s" % user)
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            logger.debug("User %s has api key pairs %s" % (user, api_key_pairs))
            if api_key_pairs:
                authserviceinfo, c = AuthServicesInfo.objects.get_or_create(user=user)
                logger.debug("User %s has api keys. Proceeding to refresh." % user)
                for api_key_pair in api_key_pairs:
                    refresh_api(api_key_pair)
                # Check our main character
                if EveCharacter.objects.filter(character_id=authserviceinfo.main_char_id).exists() is False:
                    logger.info("User %s main character id %s missing model. Clearning main character." % (user, authserviceinfo.main_char_id))
                    authserviceinfo.main_char_id = ''
                    authserviceinfo.save()
                    notify(user, "Main Character Reset", message="Your specified main character no longer has a model.\nThis could be the result of an invalid API\nYour main character ID has been reset." % api_key_pair.api_id, level="warn")
        set_state(user)
开发者ID:Aelonius,项目名称:allianceauth,代码行数:23,代码来源:tasks.py

示例9: run_alliance_corp_update

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_alliance_corp_update():
    # I am not proud of this block of code
    if EveApiManager.check_if_api_server_online():

        # Updated alliance info
        alliance_info = EveApiManager.get_alliance_information(settings.ALLIANCE_ID)

        # Populate alliance info
        if not EveManager.check_if_alliance_exists_by_id(settings.ALLIANCE_ID):
            EveManager.create_alliance_info(settings.ALLIANCE_ID, alliance_info['name'], alliance_info['ticker'],
                                            alliance_info['executor_id'], alliance_info['member_count'], False)

        alliance = EveManager.get_alliance_info_by_id(settings.ALLIANCE_ID)

        # Create the corps in the alliance
        for alliance_corp in alliance_info['member_corps']:
            corpinfo = EveApiManager.get_corporation_information(alliance_corp)
            if not EveManager.check_if_corporation_exists_by_id(corpinfo['id']):
                EveManager.create_corporation_info(corpinfo['id'], corpinfo['name'], corpinfo['ticker'],
                                                   corpinfo['members']['current'], False, alliance)

        # Create the corps in the standings
        alliance_standings = EveApiManager.get_alliance_standings()
        if alliance_standings:
            for standing_id in EveApiManager.get_alliance_standings()['alliance']:
                if int(alliance_standings['alliance'][standing_id]['standing']) >= settings.ALLIANCE_BLUE_STANDING:
                    if EveApiManager.check_if_id_is_character(standing_id):
                        pass
                    elif EveApiManager.check_if_id_is_corp(standing_id):
                        corpinfo = EveApiManager.get_corporation_information(standing_id)
                        if not EveManager.check_if_corporation_exists_by_id(standing_id):
                            EveManager.create_corporation_info(corpinfo['id'], corpinfo['name'], corpinfo['ticker'],
                                                               corpinfo['members']['current'], True, None)
                    else:
                        # Alliance id create corps
                        blue_alliance_info = EveApiManager.get_alliance_information(standing_id)

                        if not EveManager.check_if_alliance_exists_by_id(standing_id):
                            EveManager.create_alliance_info(standing_id, blue_alliance_info['name'],
                                                            blue_alliance_info['ticker'],
                                                            blue_alliance_info['executor_id'],
                                                            blue_alliance_info['member_count'], True)

                        blue_alliance = EveManager.get_alliance_info_by_id(standing_id)

                        for blue_alliance_corp in blue_alliance_info['member_corps']:
                            blue_info = EveApiManager.get_corporation_information(blue_alliance_corp)
                            if not EveManager.check_if_corporation_exists_by_id(blue_info['id']):
                                EveManager.create_corporation_info(blue_info['id'], blue_info['name'],
                                                                   blue_info['ticker'],
                                                                   blue_info['members']['current'], True, blue_alliance)

        # Update all allinace info's
        for all_alliance_info in EveManager.get_all_alliance_info():
            all_alliance_api_info = EveApiManager.get_alliance_information(all_alliance_info.alliance_id)
            if all_alliance_info.alliance_id == settings.ALLIANCE_ID:
                EveManager.update_alliance_info(all_alliance_api_info['id'], all_alliance_api_info['executor_id'],
                                                all_alliance_api_info['member_count'], False)
            else:
                if 'alliance' in alliance_standings:
                    if int(all_alliance_info.alliance_id) in alliance_standings['alliance']:
                        if int(alliance_standings['alliance'][int(all_alliance_info.alliance_id)][
                            'standing']) >= settings.ALLIANCE_BLUE_STANDING:
                            EveManager.update_alliance_info(all_alliance_api_info['id'],
                                                            all_alliance_api_info['executor_id'],
                                                            all_alliance_api_info['member_count'], True)
                        else:
                            EveManager.update_alliance_info(all_alliance_api_info['id'],
                                                            all_alliance_api_info['executor_id'],
                                                            all_alliance_api_info['member_count'], False)

                    else:
                        EveManager.update_alliance_info(all_alliance_api_info['id'],
                                                        all_alliance_api_info['executor_id'],
                                                        all_alliance_api_info['member_count'], False)
                else:
                    EveManager.update_alliance_info(all_alliance_api_info['id'],
                                                    all_alliance_api_info['executor_id'],
                                                    all_alliance_api_info['member_count'], False)

        # Update corp infos
        for all_corp_info in EveManager.get_all_corporation_info():
            alliance = None
            corpinfo = EveApiManager.get_corporation_information(all_corp_info.corporation_id)
            if corpinfo['alliance']['id'] is not None:
                alliance = EveManager.get_alliance_info_by_id(corpinfo['alliance']['id'])

            if alliance is not None and all_corp_info.alliance is not None:

                if all_corp_info.alliance.alliance_id == settings.ALLIANCE_ID:
                    EveManager.update_corporation_info(corpinfo['id'], corpinfo['members']['current'], alliance, False)
                else:
                    if int(alliance.alliance_id) in alliance_standings['alliance']:
                        if int(alliance_standings['alliance'][int(alliance.alliance_id)][
                            'standing']) >= settings.ALLIANCE_BLUE_STANDING:
                            EveManager.update_corporation_info(corpinfo['id'], corpinfo['members']['current'], alliance,
                                                               True)
                        else:
                            EveManager.update_corporation_info(corpinfo['id'], corpinfo['members']['current'], alliance,
                                                               False)
#.........这里部分代码省略.........
开发者ID:Krienas,项目名称:allianceauth,代码行数:103,代码来源:tasks.py

示例10: run_corp_update

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_corp_update():
    if EveApiManager.check_if_api_server_online() is False:
        logger.warn("Aborted updating corp and alliance models: API server unreachable")
        return
    standing_level = 'alliance'
    try:
        # get corp info for owning corp if required
        ownercorpinfo = {}
        if settings.IS_CORP:
            standing_level = 'corp'
            logger.debug("Getting information for owning corp with id %s" % settings.CORP_ID)
            ownercorpinfo = EveApiManager.get_corporation_information(settings.CORP_ID)
            if not ownercorpinfo:
                logger.error("Failed to retrieve corp info for owning corp id %s - bad corp id?" % settings.CORP_ID)
                return
    
        # check if we need to update an alliance model
        alliance_id = ''
        if ownercorpinfo and ownercorpinfo['alliance']['id']:
            alliance_id = ownercorpinfo['alliance']['id']
        elif settings.IS_CORP is False:
            alliance_id = settings.ALLIANCE_ID
    
        # get and create alliance info for owning alliance if required
        alliance = None
        if alliance_id:
            logger.debug("Getting information for owning alliance with id %s" % alliance_id)
            ownerallianceinfo = EveApiManager.get_alliance_information(alliance_id)
            if not ownerallianceinfo:
                logger.error("Failed to retrieve corp info for owning alliance id %s - bad alliance id?" % alliance_id)
                return
            if EveAllianceInfo.objects.filter(alliance_id=ownerallianceinfo['id']).exists():
                logger.debug("Updating existing owner alliance model with id %s" % alliance_id)
                EveManager.update_alliance_info(ownerallianceinfo['id'], ownerallianceinfo['executor_id'], ownerallianceinfo['member_count'], False)
            else:
                populate_alliance(alliance_id)
                alliance = EveAllianceInfo.objects.get(alliance_id=alliance_id)
    
        # create corp info for owning corp if required
        if ownercorpinfo:
            if EveCorporationInfo.objects.filter(corporation_id=ownercorpinfo['id']).exists():
                logger.debug("Updating existing owner corp model with id %s" % ownercorpinfo['id'])
                EveManager.update_corporation_info(ownercorpinfo['id'], ownercorpinfo['members']['current'], alliance, False)
            else:
                logger.info("Creating model for owning corp with id %s" % ownercorpinfo['id'])
                EveManager.create_corporation_info(ownercorpinfo['id'], ownercorpinfo['name'], ownercorpinfo['ticker'],
                                                       ownercorpinfo['members']['current'], False, alliance)

        # validate and create corp models for member corps of owning alliance
        if alliance:
            current_corps = EveCorporationInfo.objects.filter(alliance=alliance)
            for corp in current_corps:
                if corp.corporation_id in ownerallianceinfo['member_corps'] is False:
                    logger.info("Corp %s is no longer in owning alliance %s - updating model." % (corp, alliance))
                    corp.alliance = None
                    corp.save()
            for member_corp in ownerallianceinfo['member_corps']:
                if EveCorporationInfo.objects.filter(corporation_id=member_corp).exists():
                    corp = EveCorporationInfo.objects.get(corporation_id=member_corp)
                    if corp.alliance == alliance is not True:
                        logger.info("Associating corp %s with owning alliance %s" % (corp, alliance))
                        corp.alliance = alliance
                        corp.save()
                else:
                    corpinfo = EveApiManager.get_corporation_information(member_corp)
                    logger.info("Creating model for owning alliance member corp with id %s" % corpinfo['id'])
                    EveManager.create_corporation_info(corpinfo['id'], corpinfo['name'], corpinfo['ticker'],
                                                       corpinfo['members']['current'], False, alliance)

        # update existing corp models
        for corp in EveCorporationInfo.objects.all():
            update_corp.delay(corp.corporation_id)

        # update existing alliance models
        for alliance in EveAllianceInfo.objects.all():
            update_alliance.delay(alliance.alliance_id)

        # create standings
        standings = EveApiManager.get_corp_standings()
        if standings:
            standings = standings[standing_level]
            for standing in standings:
                if int(standings[standing]['standing']) >= settings.BLUE_STANDING:
                    logger.debug("Standing %s meets threshold" % standing)
                    if EveApiManager.check_if_id_is_alliance(standing):
                        logger.debug("Standing %s is an alliance" % standing)
                        if EveAllianceInfo.objects.filter(alliance_id=standing).exists():
                            alliance = EveAllianceInfo.objects.get(alliance_id=standing)
                            if alliance.is_blue is not True:
                                logger.info("Updating alliance %s as blue" % alliance)
                                alliance.is_blue = True
                                alliance.save()
                        else:
                            populate_alliance(standing, blue=True)
                    elif EveApiManager.check_if_id_is_corp(standing):
                        logger.debug("Standing %s is a corp" % standing)
                        if EveCorporationInfo.objects.filter(corporation_id=standing).exists():
                            corp = EveCorporationInfo.objects.get(corporation_id=standing)
                            if corp.is_blue is not True:
                                logger.info("Updating corp %s as blue" % corp)
#.........这里部分代码省略.........
开发者ID:johanko,项目名称:allianceauth,代码行数:103,代码来源:tasks.py

示例11: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():
    users = User.objects.all()
    logger.debug("Running api refresh on %s users." % len(users))
    for user in users:
        # Check if the api server is online
        logger.debug("Running api refresh for user %s" % user)
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            logger.debug("User %s has api key pairs %s" % (user, api_key_pairs))
            if api_key_pairs:
                valid_key = False
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                logger.debug("User %s has api keys. Proceeding to refresh." % user)
                if authserviceinfo.main_char_id:
                    if authserviceinfo.main_char_id != "":
                        #preserve old corp ID for corp change test on members
                        oldcorp_id = 0
                        if EveManager.get_character_by_id(authserviceinfo.main_char_id):
                            oldcorp_id = EveCharacter.objects.get(character_id=authserviceinfo.main_char_id).corporation_id
                            logger.debug("Determined user %s current main corp id %s" % (user, oldcorp_id))
                        for api_key_pair in api_key_pairs:
                            logger.debug("Running update on api key %s" % api_key_pair.api_id)
                            if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                                #check to ensure API key meets min spec
                                logger.info("Determined api key %s is still active." % api_key_pair.api_id)
                                still_valid = True
                                if authserviceinfo.is_blue:
                                    if settings.BLUE_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for blue user %s is no longer type account as requred." % (api_key_pair.api_id, user))
                                            still_valid = False
                                    if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for blue user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                else:
                                    if settings.MEMBER_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for user %s is no longer type account as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                    if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                if still_valid is not True:
                                    logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id)
                                    EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                    EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                                else:
                                    logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id)
                                    # Update characters
                                    characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                                       api_key_pair.api_key)
                                    EveManager.update_characters_from_list(characters)
                                    new_character = False
                                    for char in characters.result:
                                        # Ensure we have a model for all characters on key
                                        if not EveManager.check_if_character_exist(characters.result[char]['name']):
                                            new_character = True
                                            logger.debug("API key %s has a new character on the account: %s" % (api_key_pair.api_id, characters.result[char]['name']))
                                    if new_character:
                                        logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id))
                                        EveManager.create_characters_from_list(characters, user, api_key_pair.api_key)
                                    valid_key = True
                            else:
                                logger.debug("API key %s is no longer active; it and its characters will be deleted." % api_key_pair.api_id)
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)

                        if valid_key:
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            logger.debug("User %s has valid api key, checking main character %s" % (user, character))
                            if character is not None and EveManager.check_if_corporation_exists_by_id(character.corporation_id):
                                corp = EveManager.get_corporation_info_by_id(character.corporation_id)
                                main_corp_id = EveManager.get_charater_corporation_id_by_id(authserviceinfo.main_char_id)
                                main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
                                logger.debug("User %s main character %s has corp %s with alliance id %s" % (user, character, corp, main_alliance_id))
                                if (settings.IS_CORP and main_corp_id == settings.CORP_ID) or (not settings.IS_CORP and main_alliance_id == settings.ALLIANCE_ID):
                                    logger.debug("User %s corp or alliance meets membership requirements. Ensuring has required permissions and groups." % user)
                                    if not check_if_user_has_permission(user, "member"):
                                        #transition from none or blue to member
                                        if check_if_user_has_permission(user, "blue_member"):
                                            #strip blue status
                                            logger.debug("Removing user %s blue permission and group to prepare for member transition." % user)
                                            remove_member_permission(user, "blue_member")
                                            remove_user_from_group(user, settings.DEFAULT_BLUE_GROUP)
                                            AuthServicesInfoManager.update_is_blue(False, user)
                                        #add to auth group
                                        add_member_permission(user, "member")
                                        add_user_to_group(user, settings.DEFAULT_AUTH_GROUP)
                                        #add to required corp group
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                        logger.info("User %s transitioned to full member during api refresh." % user)
                                    elif corp.corporation_id != oldcorp_id:
                                        #changed corps, both corps auth'd, need to change group assignment
                                        logger.debug("User %s main character changed corp from id %s to %s, both meet membership requirements. Updating corp group." % (user, oldcorp_id, corp.corporation_id))
                                        oldcorp = EveCorporationInfo.objects.get(corporation_id=oldcorp_id)
                                        remove_user_from_group(user, generate_corp_group_name(oldcorp.corporation_name))
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                        #reset services to force new mumble names and group assignments
#.........这里部分代码省略.........
开发者ID:Tuqiri,项目名称:allianceauth,代码行数:103,代码来源:tasks.py

示例12: run_corp_update

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_corp_update():
    if not EveApiManager.check_if_api_server_online():
        logger.warn("Aborted updating corp and alliance models: API server unreachable")
        return

    # generate member corps
    for corp_id in settings.STR_CORP_IDS + settings.STR_BLUE_CORP_IDS:
        is_blue = True if corp_id in settings.STR_BLUE_CORP_IDS else False
        try:
            if EveCorporationInfo.objects.filter(corporation_id=corp_id).exists():
                update_corp.apply(args=(corp_id,), kwargs={'is_blue': is_blue})
            else:
                EveManager.create_corporation(corp_id, is_blue=is_blue)
        except ObjectNotFound:
            logger.warn('Bad corp ID in settings: %s' % corp_id)

    # generate member alliances
    for alliance_id in settings.STR_ALLIANCE_IDS + settings.STR_BLUE_ALLIANCE_IDS:
        is_blue = True if alliance_id in settings.STR_BLUE_ALLIANCE_IDS else False
        try:
            if EveAllianceInfo.objects.filter(alliance_id=alliance_id).exists():
                logger.debug("Updating existing owner alliance model with id %s" % alliance_id)
                update_alliance(alliance_id, is_blue=is_blue)
            else:
                EveManager.create_alliance(alliance_id, is_blue=is_blue)
                EveManager.populate_alliance(alliance_id)
        except ObjectNotFound:
            logger.warn('Bad alliance ID in settings: %s' % alliance_id)

    # update existing corp models
    for corp in EveCorporationInfo.objects.exclude(
            corporation_id__in=settings.STR_CORP_IDS + settings.STR_BLUE_CORP_IDS):
        update_corp.delay(corp.corporation_id)

    # update existing alliance models
    for alliance in EveAllianceInfo.objects.exclude(
            alliance_id__in=settings.STR_ALLIANCE_IDS + settings.STR_BLUE_ALLIANCE_IDS):
        update_alliance.delay(alliance.alliance_id)

    try:
        # create standings
        standings = EveApiManager.get_corp_standings()
        if standings:
            standings = standings[settings.STANDING_LEVEL]
            for standing in standings:
                if float(standings[standing]['standing']) >= settings.BLUE_STANDING:
                    logger.debug("Standing %s meets threshold" % standing)
                    if EveApiManager.check_if_id_is_alliance(standing):
                        logger.debug("Standing %s is an alliance" % standing)
                        if EveAllianceInfo.objects.filter(alliance_id=standing).exists():
                            alliance = EveAllianceInfo.objects.get(alliance_id=standing)
                            if alliance.is_blue is not True:
                                logger.info("Updating alliance %s as blue" % alliance)
                                alliance.is_blue = True
                                alliance.save()
                        else:
                            EveManager.create_alliance(standing, is_blue=True)
                    elif EveApiManager.check_if_id_is_corp(standing):
                        logger.debug("Standing %s is a corp" % standing)
                        if EveCorporationInfo.objects.filter(corporation_id=standing).exists():
                            corp = EveCorporationInfo.objects.get(corporation_id=standing)
                            if corp.is_blue is not True:
                                logger.info("Updating corp %s as blue" % corp)
                                corp.is_blue = True
                                corp.save()
                        else:
                            logger.info("Creating model for blue corp with id %s" % standing)
                            EveManager.create_corporation(standing, is_blue=True)

        # update alliance standings
        for alliance in EveAllianceInfo.objects.filter(is_blue=True):
            if int(alliance.alliance_id) in standings:
                if float(standings[int(alliance.alliance_id)]['standing']) < float(settings.BLUE_STANDING):
                    logger.info("Alliance %s no longer meets minimum blue standing threshold" % alliance)
                    alliance.is_blue = False
                    alliance.save()
            elif alliance.alliance_id not in settings.STR_BLUE_ALLIANCE_IDS:
                logger.info("Alliance %s no longer in standings" % alliance)
                alliance.is_blue = False
                alliance.save()

        # update corp standings
        for corp in EveCorporationInfo.objects.filter(is_blue=True):
            if int(corp.corporation_id) in standings:
                if float(standings[int(corp.corporation_id)]['standing']) < float(settings.BLUE_STANDING):
                    logger.info("Corp %s no longer meets minimum blue standing threshold" % corp)
                    corp.is_blue = False
                    corp.save()
            elif corp.corporation_id not in settings.STR_BLUE_CORP_IDS:
                if corp.alliance:
                    if not corp.alliance.is_blue:
                        logger.info("Corp %s and its alliance %s are no longer blue" % (corp, corp.alliance))
                        corp.is_blue = False
                        corp.save()
                else:
                    logger.info("Corp %s is no longer blue" % corp)
                    corp.is_blue = False
                    corp.save()
    except evelink.api.APIError as e:
        logger.error("Model update failed with error code %s" % e.code)
#.........这里部分代码省略.........
开发者ID:iAddz,项目名称:allianceauth,代码行数:103,代码来源:tasks.py

示例13: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():
    users = User.objects.all()

    for user in users:
        # Check if the api server is online
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            if api_key_pairs:
                valid_key = False
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                print 'Running update on user: ' + user.username
                if authserviceinfo.main_char_id:
                    if authserviceinfo.main_char_id != "":
                        #preserve old corp ID for corp change test on members
                        oldcorp_id = 0
                        if EveManager.get_character_by_id(authserviceinfo.main_char_id):
                            oldcorp_id = EveCharacter.objects.get(character_id=authserviceinfo.main_char_id).corporation_id
                        for api_key_pair in api_key_pairs:
                            print 'Running on ' + api_key_pair.api_id + ':' + api_key_pair.api_key
                            if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                                #check to ensure API key meets min spec
                                still_valid = True
                                if authserviceinfo.is_blue:
                                    if settings.BLUE_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            still_valid = False
                                    if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            still_valid = False
                                else:
                                    if settings.MEMBER_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            still_valid = False
                                    if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            still_valid = False
                                if still_valid is not True:
                                    EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                    EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                                else:                                    
                                    # Update characters
                                    characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                                       api_key_pair.api_key)
                                    EveManager.update_characters_from_list(characters)
                                    new_character = False
                                    for char in characters.result:
                                        # Ensure we have a model for all characters on key
                                        if not EveManager.check_if_character_exist(characters.result[char]['name']):
                                            new_character = True
                                    if new_character:
                                        EveManager.create_characters_from_list(characters, user, api_key_pair.api_key)
                                    valid_key = True
                            else:
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)

                        if valid_key:
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            if character is not None and EveManager.check_if_corporation_exists_by_id(character.corporation_id):
                                corp = EveManager.get_corporation_info_by_id(character.corporation_id)
                                main_corp_id = EveManager.get_charater_corporation_id_by_id(authserviceinfo.main_char_id)
                                main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
                                if (settings.IS_CORP and main_corp_id == settings.CORP_ID) or (not settings.IS_CORP and main_alliance_id == settings.ALLIANCE_ID):
                                    if not check_if_user_has_permission(user, "member"):
                                        #transition from none or blue to member
                                        if check_if_user_has_permission(user, "blue_member"):
                                            #strip blue status
                                            remove_member_permission(user, "blue_member")
                                            remove_user_from_group(user, settings.DEFAULT_BLUE_GROUP)
                                            AuthServicesInfoManager.update_is_blue(False, user)
                                        #add to auth group
                                        add_member_permission(user, "member")
                                        add_user_to_group(user, settings.DEFAULT_AUTH_GROUP)
                                        #add to required corp group
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                    elif corp.corporation_id != oldcorp_id:
                                        #changed corps, both corps auth'd, need to change group assignment
                                        oldcorp = EveCorporationInfo.objects.get(corporation_id=oldcorp_id)
                                        remove_user_from_group(user, generate_corp_group_name(oldcorp.corporation_name))
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                        #reset services to force new mumble names and group assignments
                                        deactivate_services(user)
                                elif corp is not None:
                                    if corp.is_blue is not True:
                                        if check_if_user_has_permission(user, "member"):
                                            #transition from member to nobody
                                            disable_alliance_member(user, authserviceinfo.main_char_id)
                                        elif check_if_user_has_permission(user, "blue_member"):
                                            #transition from blue to nobody
                                            disable_blue_member(user)
                                        else:
                                            #stay nobody, make sure no services
                                            deactivate_services(user)
                                    else:
                                        if check_if_user_has_permission(user, "member"):
                                            #remove auth member to prepare for member to blue transition
                                            disable_alliance_member(user, authserviceinfo.main_char_id)
                                        if not check_if_user_has_permission(user, "blue_member"):
                                            #perform nobody to blue transition
                                            add_member_permission(user, "blue_member")
#.........这里部分代码省略.........
开发者ID:Ashisacat,项目名称:allianceauth,代码行数:103,代码来源:tasks.py

示例14: prime_kills

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def prime_kills():
    if EveApiManager.check_if_api_server_online():
        kill_api = EveApiManager.get_corp_kills(settings.ALLIANCE_EXEC_CORP_ID, settings.ALLIANCE_EXEC_CORP_VCODE)
        for kill in kill_api.result:
            EveManager.create_corporation_kill(kill)
开发者ID:RZN-FFEvo,项目名称:corpauth,代码行数:7,代码来源:tasks.py

示例15: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import check_if_api_server_online [as 别名]
def run_api_refresh():
    users = User.objects.all()
    logger.debug("Running api refresh on %s users." % len(users))
    for user in users:
        # Check if the api server is online
        logger.debug("Running api refresh for user %s" % user)
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            logger.debug("User %s has api key pairs %s" % (user, api_key_pairs))
            if api_key_pairs:
                authserviceinfo, c = AuthServicesInfo.objects.get_or_create(user=user)
                logger.debug("User %s has api keys. Proceeding to refresh." % user)
                for api_key_pair in api_key_pairs:
                    logger.debug("Running update on api key %s" % api_key_pair.api_id)
                    if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                        # check to ensure API key meets min spec
                        logger.info("Determined api key %s is still active." % api_key_pair.api_id)
                        still_valid = True
                        state = determine_membership_by_user(user)
                        if state == "BLUE":
                            if settings.BLUE_API_ACCOUNT:
                                type = EveApiManager.check_api_is_type_account(
                                    api_key_pair.api_id, api_key_pair.api_key
                                )
                                if type == None:
                                    api_key_pair.error_count += 1
                                    api_key_pair.save()
                                    logger.info(
                                        "API key %s incurred an error checking if type account. Error count is now %s"
                                        % (api_key_pair.api_id, api_key_pair.error_count)
                                    )
                                    still_valid = None
                                elif type == False:
                                    logger.info(
                                        "Determined api key %s for blue user %s is no longer type account as requred."
                                        % (api_key_pair.api_id, user)
                                    )
                                    still_valid = False
                            full = EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key)
                            if full == None:
                                api_key_pair.error_count += 1
                                api_key_pair.save()
                                logger.info(
                                    "API key %s incurred an error checking if meets mask requirements. Error count is now %s"
                                    % (api_key_pair.api_id, api_key_pair.error_count)
                                )
                                still_valid = None
                            elif full == False:
                                logger.info(
                                    "Determined api key %s for blue user %s no longer meets minimum access mask as required."
                                    % (api_key_pair.api_id, user)
                                )
                                still_valid = False
                        elif state == "MEMBER":
                            if settings.MEMBER_API_ACCOUNT:
                                type = EveApiManager.check_api_is_type_account(
                                    api_key_pair.api_id, api_key_pair.api_key
                                )
                                if type == None:
                                    api_key_pair.error_count += 1
                                    api_key_pair.save()
                                    logger.info(
                                        "API key %s incurred an error checking if type account. Error count is now %s"
                                        % (api_key_pair.api_id, api_key_pair.error_count)
                                    )
                                    still_valid = None
                                elif type == False:
                                    logger.info(
                                        "Determined api key %s for user %s is no longer type account as required."
                                        % (api_key_pair.api_id, user)
                                    )
                                    still_valid = False
                            full = EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key)
                            if full == None:
                                api_key_pair.error_count += 1
                                api_key_pair.save()
                                logger.info(
                                    "API key %s incurred an error checking if meets mask requirements. Error count is now %s"
                                    % (api_key_pair.api_id, api_key_pair.error_count)
                                )
                                still_valid = None
                            elif full == False:
                                logger.info(
                                    "Determined api key %s for user %s no longer meets minimum access mask as required."
                                    % (api_key_pair.api_id, user)
                                )
                                still_valid = False
                        if still_valid == None:
                            if api_key_pair.error_count >= 3:
                                logger.info(
                                    "API key %s has incurred 3 or more errors. Assuming invalid." % api_key_pair.api_id
                                )
                                still_valid = False
                        if still_valid == False:
                            logger.debug(
                                "API key %s has failed validation; it and its characters will be deleted."
                                % api_key_pair.api_id
                            )
                            EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                            EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
#.........这里部分代码省略.........
开发者ID:kallama,项目名称:allianceauth,代码行数:103,代码来源:tasks.py


注:本文中的services.managers.eve_api_manager.EveApiManager.check_if_api_server_online方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。