Last active
August 29, 2015 14:12
-
-
Save tyler274/f136e9b65ee9027033e4 to your computer and use it in GitHub Desktop.
possible fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run every 3 hours | |
@periodic_task(run_every=crontab(minute=0, hour="*/3")) | |
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) | |
for character in characters | |
if character = EveManager.get_character_by_id(authserviceinfo.main_char_id): | |
# Check our main character | |
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 | |
#use break to avoid unnecessary calls | |
break | |
elif corp is not None: | |
if corp.is_blue is not True: | |
deactivate_services(user) | |
else: | |
deactivate_services(user) | |
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' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment