def fetch_mailinglists(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MailingLists(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return listIDs = handler.autoparse_shared_list(api_data.mailingLists, MailingList, ('listID', ), character, pre_save=True) unsubscribed = character.mailinglist_set.exclude(listID__in=listIDs) for desub in unsubscribed: desub.owners.remove(character) target.updated(api_data)
def fetch_mailinglists(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MailingLists(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return listIDs = handler.autoparse_shared_list(api_data.mailingLists, MailingList, ('listID',), character, pre_save=True) unsubscribed = character.mailinglist_set.exclude(listID__in=listIDs) for desub in unsubscribed: desub.owners.remove(character) target.updated(api_data)
def fetch_mails(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MailMessages(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return mails = handler.autoparse_shared_list(api_data.messages, MailMessage, ('messageID',), character, pre_save=True) unfetched_mails = MailMessage.objects.filter( owners__in=[character.pk], pk__in=mails, broken=False, raw_message=None) EveName.objects.populate() if unfetched_mails.count() > 0: mail_bodies = auth.char.MailBodies(characterID=target.owner, IDs=[mail.messageID for mail in unfetched_mails]) for mail_body in mail_bodies.messages: try: mail = MailMessage.objects.get(messageID=mail_body.messageID) mail.raw_message = mail_body.data mail.populate_receivers() mail.save() except MailMessage.DoesNotExist: log.error('Could not fetch message body for messageID {0} belonging to character "{1}".'.format( mail_body.messageID, character )) #except: # note.broken = True # note.save() target.updated(api_data)
def fetch_mails(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MailMessages(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return mails = handler.autoparse_shared_list(api_data.messages, MailMessage, ('messageID', ), character, pre_save=True) unfetched_mails = MailMessage.objects.filter(owners__in=[character.pk], pk__in=mails, broken=False, raw_message=None) EveName.objects.populate() if unfetched_mails.count() > 0: mail_bodies = auth.char.MailBodies( characterID=target.owner, IDs=[mail.messageID for mail in unfetched_mails]) for mail_body in mail_bodies.messages: try: mail = MailMessage.objects.get(messageID=mail_body.messageID) mail.raw_message = mail_body.data mail.populate_receivers() mail.save() except MailMessage.DoesNotExist: log.error( 'Could not fetch message body for messageID {0} belonging to character "{1}".' .format(mail_body.messageID, character)) # except: # note.broken = True # note.save() target.updated(api_data)