def migrate_spell_info(apps, schema_editor): version = get_lol_last_version() data_folder_path = os.path.join(PROJECT_PATH, 'data') version_path = os.path.join(data_folder_path, version) all_data_path = os.path.join(version_path, 'spell_all.json') if not os.path.exists(version_path): if not os.path.exists(data_folder_path): os.mkdir(data_folder_path) os.mkdir(version_path) if not os.path.exists(all_data_path): response = requests.get((LOL_URL['STATIC_SPELL_ALL_DATA'] % version)) if response.status_code == 200: make_json_file(response.json(), all_data_path) with open(all_data_path) as json_file: json_data = json.load(json_file) SpellModel = apps.get_model('main', 'Spell') for key, value in json_data['data'].items(): try: spell_model = SpellModel.objects.get(pk=int(value['key'])) except SpellModel.DoesNotExist: spell_model = SpellModel(key=int(value['key']), id=key) spell_model.save()
def get_client_data(self): latest_version = get_lol_last_version() return { 'name': self.name, 'level': self.level, 'icon_url': (LOL_URL['PROFILE_ICON'] % (latest_version, str(self.icon_id))), }
def get_client_data(self): version = get_lol_last_version() champion_info = load_champion_info(self.champion_id) second_diff = (int(round(time.time() * 1000)) - self.timestamp) / 1000 diff_format = '' if second_diff < 60: diff_format = ('%d초 전' % second_diff) elif second_diff < 3600: diff_format = ('%d분 전' % math.ceil(second_diff / 60)) elif second_diff < 86400: diff_format = ('%d시간 전' % math.ceil(second_diff / 3600)) else: diff_format = ('%d일 전' % math.ceil(second_diff / 86400)) queue_type = '?' if self.queue == 450: queue_type = '칼바람' elif self.queue == 420: queue_type = '솔랭' elif self.queue == 430: queue_type = '일반' elif self.queue == 440: queue_type = '자유랭' return { 'game_id': self.game_id, 'champion_name': champion_info['name'], 'champion_icon_url': (LOL_URL['CHAMPION_ICON'] % (version, champion_info['id'])), 'queue': queue_type, 'time': datetime.fromtimestamp(self.timestamp / 1000).strftime( "%Y년 %m월 %d일 %p %I시 %M분".encode('unicode-escape').decode( )).encode().decode('unicode-escape'), 'diff_time': diff_format, 'role': self.role, 'lane': self.lane, }
def load_champion_info(champion_key): version = get_lol_last_version() data_folder_path = os.path.join(PROJECT_PATH, 'data') version_path = os.path.join(data_folder_path, version) champion_data_path = os.path.join(version_path, str(champion_key) + '.json') if not os.path.exists(champion_data_path): raise FileNotFoundError('the %d champion data does not exist.' % champion_key) if champion_key in champions.keys(): return champions[champion_key] with open(champion_data_path) as json_file: json_data = json.load(json_file) key = list(json_data['data'].keys())[0] champions[champion_key] = json_data['data'][key] return champions[champion_key]
def update_champion_info(): from main.models import Champion version = get_lol_last_version() data_folder_path = os.path.join(PROJECT_PATH, 'data') version_path = os.path.join(data_folder_path, version) all_data_path = os.path.join(version_path, 'champion_all.json') if not os.path.exists(version_path): if not os.path.exists(data_folder_path): os.mkdir(data_folder_path) os.mkdir(version_path) if not os.path.exists(all_data_path): response = requests.get( (LOL_URL['STATIC_CHAMPION_ALL_DATA'] % version)) if response.status_code == 200: make_json_file(response.json(), all_data_path) with open(all_data_path) as json_file: json_data = json.load(json_file) for key, value in json_data['data'].items(): try: champion_model = Champion.objects.get(pk=int(value['key'])) except Champion.DoesNotExist: champion_model = Champion(key=int(value['key']), id=key) champion_model.save() champion_data_path = os.path.join(version_path, str(value['key']) + '.json') if not os.path.exists(champion_data_path): response = requests.get( (LOL_URL['STATIC_CHAMPION_DATA'] % (version, key))) if response.status_code == 200: make_json_file(response.json(), champion_data_path)
def get_client_data(self): version = get_lol_last_version() champion_info = load_champion_info(self.champion_id) if self.spell_1_id in cache_spell_ids.keys(): spell_1_id = cache_spell_ids[self.spell_1_id] else: spell_1_id = self.spell_1.id cache_spell_ids[self.spell_1_id] = spell_1_id if self.spell_2_id in cache_spell_ids.keys(): spell_2_id = cache_spell_ids[self.spell_2_id] else: spell_2_id = self.spell_2.id cache_spell_ids[self.spell_2_id] = spell_2_id return { 'game_id': self.game_id, 'team_id': self.team_id, 'summoner_name': self.display_summoner_name, 'champion_name': champion_info['name'], 'champion_icon_url': (LOL_URL['CHAMPION_ICON'] % (version, champion_info['id'])), 'champion_level': self.champ_level, 'spell_1_icon_url': (LOL_URL['SPELL_ICON'] % (version, spell_1_id)), 'spell_2_icon_url': (LOL_URL['SPELL_ICON'] % (version, spell_2_id)), 'item_0_icon_url': (LOL_URL['ITEM_ICON'] % (version, self.item_0)) if self.item_0 != 0 else 'empty', 'item_1_icon_url': (LOL_URL['ITEM_ICON'] % (version, self.item_1)) if self.item_1 != 0 else 'empty', 'item_2_icon_url': (LOL_URL['ITEM_ICON'] % (version, self.item_2)) if self.item_2 != 0 else 'empty', 'item_3_icon_url': (LOL_URL['ITEM_ICON'] % (version, self.item_3)) if self.item_3 != 0 else 'empty', 'item_4_icon_url': (LOL_URL['ITEM_ICON'] % (version, self.item_4)) if self.item_4 != 0 else 'empty', 'item_5_icon_url': (LOL_URL['ITEM_ICON'] % (version, self.item_5)) if self.item_5 != 0 else 'empty', 'item_6_icon_url': (LOL_URL['ITEM_ICON'] % (version, self.item_6)) if self.item_6 != 0 else 'empty', 'kills': self.kills, 'deaths': self.deaths, 'assists': self.assists, }