def reload_configs(request): flush_all_tables() response = {} json_data = open(CONFIG_FILE_PATH, "r") try: configjson = simplejson.load(json_data) except ValueError: response['status_code'] = 400 response["response"] = "Error parsing json file" return HttpResponse(simplejson.dumps(response), mimetype="application/json") json_data.close() champions = configjson["champions"] for champion in champions: championobject = None try: championobject = Champion.objects.get(name=champion["name"]) except ObjectDoesNotExist: positions = champion["positions"] championobject = Champion(name=champion["name"], top=positions["top"], jungle=positions["jungle"], mid=positions["mid"], adc=positions["adc"], support=positions["support"]) championobject.save() counterlist = CounterList(champion=championobject) counterlist.save() else: update_positions(championobject, champion["positions"]) update_counters(championobject, champion["counters"]) update_champion_compositions(championobject, champion["compositions"]) response['status_code'] = 200 response["response"] = "Reload successful" return HttpResponse(simplejson.dumps(response), mimetype="application/json")
def update_counters(champion, counters): for counter in counters: championcounter = None try: championcounter = Champion.objects.get(name=counter["name"]) except ObjectDoesNotExist: championcounter = Champion(name=counter["name"], top=0, jungle=0, mid=0, adc=0, support=0) championcounter.save() counterlist = CounterList(champion=championcounter) counterlist.save() counterlist = champion.counterlist c = Counter(champion=championcounter, strength=counter["strength"], championlist=counterlist) c.save()
def getChampionName(championId, region): champion_name = '' r = R.r r_champion_name_key = 'champion.name.{0}.value'.format(championId) champion_name = r.get(r_champion_name_key) if not champion_name: try: champion_name = Champion.objects.get(champion_id=championId).name except: response = retrieveChampionDataById(region, championId) if type(response) is dict: champion = Champion(champion_id=championId, name=response['name'], title=response['title']) champion.save() champion_name = champion.name r.set(r_champion_name_key, champion_name) return champion_name
import json with open('res/champion.json', encoding="utf8") as inputFile: data = json.load(inputFile) champions = data['data'] for key, currentChamp in champions.items(): entry = Champion( name=currentChamp['name'], sprite=currentChamp['image']['full'], hp=currentChamp['stats']['hp'], hpperlevel=currentChamp['stats']['hpperlevel'], mp=currentChamp['stats']['mp'], mpperlevel=currentChamp['stats']['mpperlevel'], movespeed=currentChamp['stats']['movespeed'], armor=currentChamp['stats']['armor'], armorperlevel=currentChamp['stats']['armorperlevel'], spellblock=currentChamp['stats']['spellblock'], spellblockperlevel=currentChamp['stats']['spellblockperlevel'], attackrange=currentChamp['stats']['attackrange'], hpregen=currentChamp['stats']['hpregen'], hpregenperlevel=currentChamp['stats']['hpregenperlevel'], mpregen=currentChamp['stats']['mpregen'], mpregenperlevel=currentChamp['stats']['mpregenperlevel'], crit=currentChamp['stats']['crit'], critperlevel=currentChamp['stats']['critperlevel'], attackdamage=currentChamp['stats']['attackdamage'], attackdamageperlevel=currentChamp['stats']['attackdamageperlevel'], attackspeedperlevel=currentChamp['stats']['attackspeedperlevel'], attackspeed=currentChamp['stats']['attackspeed']) entry.save()