def update_information(self, model): """ Updates a given capsuleer model and triggers an update of the corasponding CapsuleerCorpHistory model. :param model: the model of a capsuleer to be updated """ log.info('Updating the information for capsuleer {}'.format(model.id)) self._isinstance(model) capsuleer_info = evelink_eve.character_info_from_id(model.id).result capsuleer_corp_history.update_from_id(model.id) capsuleer_sec_history.create(**{ 'id': model.id, 'sec_status': capsuleer_info['sec_status'], }) ensure_corp_exists(capsuleer_info['corp']['id']) # TODO: Potential DB performance increase in only updating columns that # have changed. self.update(model, **{ 'name': capsuleer_info['name'], 'security_status': capsuleer_info['sec_status'], 'last_checked': datetime.now(), 'corporation_id': capsuleer_info['corp']['id'], })
def update_from_id(self, id): """ Given a capsuler ID updates the capsuleers corporation history. :param id: id of the capsuleer to update """ api_history = evelink_eve.character_info_from_id(id).result['history'] db_history = self.get_capsuleer_history(id).all() if len(api_history) != len(db_history): api_history = list(reversed(api_history)) db_history = list(reversed(db_history)) for index, corp in enumerate(api_history[len(db_history) - 1:]): ensure_corp_exists(corp['corp_id']) model_data = { 'capsuleer_id': id, 'corporation_id': corp['corp_id'], 'start_time': evelink_ts_to_datetime(corp['start_ts']), } # TODO: Add logic for adding end_time self.create(**model_data)