本文整理汇总了Python中services.managers.eve_api_manager.EveApiManager类的典型用法代码示例。如果您正苦于以下问题:Python EveApiManager类的具体用法?Python EveApiManager怎么用?Python EveApiManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EveApiManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean
def clean(self):
super(UpdateKeyForm, self).clean()
if 'api_id' in self.cleaned_data and 'api_key' in self.cleaned_data:
if EveManager.check_if_api_key_pair_exist(self.cleaned_data['api_id']):
logger.debug("UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data['api_id'])
raise forms.ValidationError(u'API key already exist')
if EveApiManager.api_key_is_valid(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API key is invalid')
chars = EveApiManager.get_characters_from_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']).result
states = []
states.append(self.user_state)
for char in chars:
evechar = EveCharacter()
evechar.character_name = chars[char]['name']
evechar.corporation_id = chars[char]['corp']['id']
evechar.alliance_id = chars[char]['alliance']['id']
state = determine_membership_by_character(evechar)
logger.debug("API ID %s character %s has state %s" % (self.cleaned_data['api_id'], evechar, state))
states.append(state)
if 'MEMBER' in states:
if EveApiManager.validate_member_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API must meet member requirements')
if 'BLUE' in states:
if EveApiManager.validate_blue_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
raise forms.ValidationError(u'API must meet blue requirements')
return self.cleaned_data
示例2: run_alliance_corp_update
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)
示例3: clean
def clean(self):
if EveManager.check_if_api_key_pair_exist(self.cleaned_data['api_id']):
raise forms.ValidationError(u'API key already exist')
check_blue = False
try:
check_blue = self.cleaned_data['is_blue']
except:
pass
if check_blue:
if settings.BLUE_API_ACCOUNT:
if not EveApiManager.check_api_is_type_account(self.cleaned_data['api_id'],
self.cleaned_data['api_key']):
raise forms.ValidationError(u'API not of type account')
if not EveApiManager.check_blue_api_is_full(self.cleaned_data['api_id'],
self.cleaned_data['api_key']):
raise forms.ValidationError(u'API supplied is too restricted. Minimum access mask is ' + str(settings.BLUE_API_MASK))
else:
if settings.MEMBER_API_ACCOUNT:
if not EveApiManager.check_api_is_type_account(self.cleaned_data['api_id'],
self.cleaned_data['api_key']):
raise forms.ValidationError(u'API not of type account')
if not EveApiManager.check_api_is_full(self.cleaned_data['api_id'],
self.cleaned_data['api_key']):
raise forms.ValidationError(u'API supplied is too restricted. Minimum access mask is ' + str(settings.MEMBER_API_MASK))
return self.cleaned_data
示例4: run_api_refresh
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'
示例5: update_corp
def update_corp(id):
corp = EveCorporationInfo.objects.get(corporation_id=id)
logger.debug("Updating corp %s" % corp)
corpinfo = EveApiManager.get_corporation_information(corp.corporation_id)
if corpinfo:
alliance = None
if EveAllianceInfo.objects.filter(alliance_id=corpinfo['alliance']['id']).exists():
alliance = EveAllianceInfo.objects.get(alliance_id=corpinfo['alliance']['id'])
EveManager.update_corporation_info(corpinfo['id'], corpinfo['members']['current'], alliance, corp.is_blue)
elif EveApiManager.check_if_corp_exists(corp.corporation_id) is False:
logger.info("Corp %s has closed. Deleting model" % corp)
corp.delete()
示例6: refresh_api
def refresh_api(api):
logger.debug('Running update on api key %s' % api.api_id)
still_valid = True
try:
EveApiManager.validate_api(api.api_id, api.api_key, api.user)
# Update characters
characters = EveApiManager.get_characters_from_api(api.api_id, api.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']):
logger.debug(
"API key %s has a new character on the account: %s" % (api.api_id, characters.result[char]['name']))
new_character = True
if new_character:
logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api.api_id))
EveManager.create_characters_from_list(characters, api.user, api.api_id)
current_chars = EveCharacter.objects.filter(api_id=api.api_id)
for c in current_chars:
if not int(c.character_id) in characters.result:
logger.info("Character %s no longer found on API ID %s" % (c, api.api_id))
c.delete()
except evelink.api.APIError as e:
logger.warning('Received unexpected APIError (%s) while updating API %s' % (e.code, api.api_id))
except EveApiManager.ApiInvalidError:
logger.debug("API key %s is no longer valid; it and its characters will be deleted." % api.api_id)
notify(api.user, "API Failed Validation", message="Your API key ID %s is no longer valid." % api.api_id,
level="danger")
still_valid = False
except EveApiManager.ApiAccountValidationError:
logger.info(
"Determined api key %s for user %s no longer meets account access requirements." % (api.api_id, api.user))
notify(api.user, "API Failed Validation",
message="Your API key ID %s is no longer account-wide as required." % api.api_id, level="danger")
still_valid = False
except EveApiManager.ApiMaskValidationError as e:
logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (
api.api_id, api.user))
notify(api.user, "API Failed Validation",
message="Your API key ID %s no longer meets access mask requirements. Required: %s Got: %s" % (
api.api_id, e.required_mask, e.api_mask), level="danger")
still_valid = False
except EveApiManager.ApiServerUnreachableError as e:
logger.warn("Error updating API %s\n%s" % (api.api_id, str(e)))
finally:
if not still_valid:
EveManager.delete_characters_by_api_id(api.api_id, api.user.id)
EveManager.delete_api_key_pair(api.api_id, api.user.id)
notify(api.user, "API Key Deleted",
message="Your API key ID %s is invalid. It and its associated characters have been deleted." % api.api_id,
level="danger")
示例7: api_sso_validate
def api_sso_validate(request, tokens, api_id):
logger.debug('api_sso_validate called by user %s for api %s' % (request.user, api_id))
api = get_object_or_404(EveApiKeyPair, api_id=api_id)
if api.user and api.user != request.user:
logger.warning('User %s attempting to take ownership of api %s from %s' % (request.user, api_id, api.user))
messages.warning(request, 'API %s already claimed by user %s' % (api_id, api.user))
return redirect('auth_api_key_management')
elif api.sso_verified:
logger.debug('API %s has already been verified.' % api_id)
messages.info(request, 'API %s has already been verified' % api_id)
return redirect('auth_api_key_management')
token = tokens[0]
logger.debug('API %s has not been verified. Checking if token for %s matches.' % (api_id, token.character_name))
characters = EveApiManager.get_characters_from_api(api.api_id, api.api_key).result
if token.character_id in characters:
api.user = request.user
api.sso_verified = True
api.save()
EveCharacter.objects.filter(character_id__in=characters).update(user=request.user, api_id=api_id)
messages.success(request, 'Confirmed ownership of API %s' % api.api_id)
auth, c = AuthServicesInfo.objects.get_or_create(user=request.user)
if not auth.main_char_id:
return redirect('auth_characters')
return redirect('auth_api_key_management')
else:
messages.warning(request, '%s not found on API %s. Please SSO as a character on the API.' % (token.character_name, api.api_id))
return render(request, 'registered/apisso.html', context={'api':api})
示例8: run_api_refresh
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)
示例9: run_api_refresh
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)
示例10: add_api_key
def add_api_key(request):
logger.debug("add_api_key called by user %s" % request.user)
user_state = determine_membership_by_user(request.user)
if request.method == "POST":
form = UpdateKeyForm(request.POST)
form.user_state = user_state
logger.debug("Request type POST with form valid: %s" % form.is_valid())
if form.is_valid():
EveManager.create_api_keypair(form.cleaned_data["api_id"], form.cleaned_data["api_key"], request.user)
# Grab characters associated with the key pair
characters = EveApiManager.get_characters_from_api(
form.cleaned_data["api_id"], form.cleaned_data["api_key"]
)
EveManager.create_characters_from_list(characters, request.user, form.cleaned_data["api_id"])
logger.info("Successfully processed api add form for user %s" % request.user)
return HttpResponseRedirect("/api_key_management/")
else:
logger.debug("Form invalid: returning to form.")
else:
logger.debug("Providing empty update key form for user %s" % request.user)
form = UpdateKeyForm()
form.user_state = user_state
context = {"form": form, "apikeypairs": EveManager.get_api_key_pairs(request.user.id)}
return render_to_response("registered/addapikey.html", context, context_instance=RequestContext(request))
示例11: update_alliance
def update_alliance(id):
alliance = EveAllianceInfo.objects.get(alliance_id=id)
corps = EveCorporationInfo.objects.filter(alliance=alliance)
logger.debug("Updating alliance %s with %s member corps" % (alliance, len(corps)))
allianceinfo = EveApiManager.get_alliance_information(alliance.alliance_id)
if allianceinfo:
EveManager.update_alliance_info(allianceinfo['id'], allianceinfo['executor_id'],
allianceinfo['member_count'], alliance.is_blue)
for corp in corps:
if corp.corporation_id in allianceinfo['member_corps'] is False:
logger.info("Corp %s no longer in alliance %s" % (corp, alliance))
corp.alliance = None
corp.save()
populate_alliance(alliance.alliance_id, blue=alliance.is_blue)
elif EveApiManager.check_if_alliance_exists(alliance.alliance_id) is False:
logger.info("Alliance %s has closed. Deleting model" % alliance)
alliance.delete()
示例12: clean
def clean(self):
super(UpdateKeyForm, self).clean()
if "api_id" in self.cleaned_data and "api_key" in self.cleaned_data:
try:
if EveManager.check_if_api_key_pair_exist(self.cleaned_data["api_id"]):
logger.debug(
"UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data["api_id"]
)
raise forms.ValidationError(u"API key already exist")
if EveApiManager.api_key_is_valid(self.cleaned_data["api_id"], self.cleaned_data["api_key"]) is False:
raise forms.ValidationError(u"API key is invalid")
chars = EveApiManager.get_characters_from_api(
self.cleaned_data["api_id"], self.cleaned_data["api_key"]
).result
states = []
states.append(self.user_state)
for char in chars:
evechar = EveCharacter()
evechar.character_name = chars[char]["name"]
evechar.corporation_id = chars[char]["corp"]["id"]
evechar.alliance_id = chars[char]["alliance"]["id"]
state = determine_membership_by_character(evechar)
logger.debug("API ID %s character %s has state %s" % (self.cleaned_data["api_id"], evechar, state))
states.append(state)
if "MEMBER" in states:
if (
EveApiManager.validate_member_api(self.cleaned_data["api_id"], self.cleaned_data["api_key"])
is False
):
raise forms.ValidationError(u"API must meet member requirements")
if "BLUE" in states:
if (
EveApiManager.validate_blue_api(self.cleaned_data["api_id"], self.cleaned_data["api_key"])
is False
):
raise forms.ValidationError(u"API must meet blue requirements")
return self.cleaned_data
except evelink.api.APIError as e:
logger.debug("Got error code %s while validating API %s" % (e.code, self.cleaned_data["api_id"]))
if int(e.code) in [221, 222]:
raise forms.ValidationError("API key failed validation")
else:
raise forms.ValidationError("Failed to reach API servers")
示例13: run_databaseUpdate
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)
示例14: run_api_refresh
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'
示例15: corputils_search
def corputils_search(request, corpid=settings.CORP_ID):
logger.debug("corputils_search called by user %s" % request.user)
corp = EveCorporationInfo.objects.get(corporation_id=corpid)
if request.method == 'POST':
form = CorputilsSearchForm(request.POST)
logger.debug("Request type POST contains form valid: %s" % form.is_valid())
if form.is_valid():
# Really dumb search and only checks character name
# This can be improved but it does the job for now
searchstring = form.cleaned_data['search_string']
logger.debug("Searching for player with character name %s for user %s" % (searchstring, request.user))
if settings.IS_CORP:
try:
member_list = EveApiManager.get_corp_membertracking(settings.CORP_API_ID, settings.CORP_API_VCODE)
except APIError:
logger.debug("Corp API does not have membertracking scope, using EveWho data instead.")
member_list = EveWhoManager.get_corporation_members(corpid)
else:
member_list = EveWhoManager.get_corporation_members(corpid)
Member = namedtuple('Member', ['name', 'main', 'api_registered'])
members = []
for memberid, member_data in member_list.items():
if searchstring.lower() in member_data["name"].lower():
try:
char = EveCharacter.objects.get(character_name=member_data["name"])
user = char.user
mainid = int(AuthServicesInfoManager.get_auth_service_info(user=user).main_char_id)
mainname = EveCharacter.objects.get(character_id=mainid).character_name
api_registered = True
except EveCharacter.DoesNotExist:
api_registered = False
mainname = ""
members.append(Member(name=member_data["name"], main=mainname, api_registered=api_registered))
logger.info("Found %s members for user %s matching search string %s" % (len(members), request.user, searchstring))
context = {'corp': corp, 'members': members, 'search_form': CorputilsSearchForm()}
return render_to_response('registered/corputilssearchview.html',
context, context_instance=RequestContext(request))
else:
logger.debug("Form invalid - returning for user %s to retry." % request.user)
context = {'corp': corp, 'members': None, 'search_form': CorputilsSearchForm()}
return render_to_response('registered/corputilssearchview.html',
context, context_instance=RequestContext(request))
else:
logger.debug("Returning empty search form for user %s" % request.user)
return HttpResponseRedirect("/corputils/")