def get_raid_boss_cp(mon_id): cp = 0 if int(mon_id) > 0: pokemon_file = open_json_file("pokemon") cp = pokemon_file.get(str(mon_id), 0) return cp
def get_mons(): mons = [] monList =[] mondata = open_json_file('pokemon') with open('raidmons.json') as f: raidmon = json.load(f) for mons in raidmon: for mon in mons['DexID']: lvl = mons['Level'] if str(mon).find("_") > -1: mon_split = str(mon).split("_") mon = mon_split[0] frmadd = mon_split[1] else: frmadd = "00" mon = '{:03d}'.format(int(mon)) monPic = '/asset/pokemon_icons/pokemon_icon_' + mon + '_00.png' monName = 'unknown' monid = int(mon) if str(monid) in mondata: monName = i8ln(mondata[str(monid)]["name"]) monJson = ({'filename': monPic, 'mon': monid, 'name': monName, 'lvl': lvl}) monList.append(monJson) return jsonify(monList)
def __init__(self, args): self.__application_args = args self.pokemon_file = open_json_file('pokemon') self.gyminfo = None self.gyminfo_refresh = None self.loop = None self.loop_started = Event() self.loop_tid = None self.t_asyncio_loop = Thread(name='webhook_asyncio_loop', target=self.__start_asyncio_loop) self.t_asyncio_loop.daemon = False self.t_asyncio_loop.start()
def get_pokemon(self): mondata = open_json_file('pokemon') # Why o.O stripped_mondata = {} for mon_id in mondata: stripped_mondata[mondata[str(mon_id)]["name"]] = mon_id if os.environ['LANGUAGE'] != "en": try: localized_name = i8ln(mondata[str(mon_id)]["name"]) stripped_mondata[localized_name] = mon_id except KeyError: pass return {'mondata': mondata, 'locale': stripped_mondata}
def get_raids(): raids = [] eggIdsByLevel = [1, 1, 2, 2, 3] data = db_wrapper.get_gym_infos() mondata = open_json_file('pokemon') hashdata = json.loads(getAllHash('raid')) for file in glob.glob("ocr/www_hash/raid_*.jpg"): unkfile = re.search('raid_(-?\d+)_(-?\d+)_((?s).*)\.jpg', file) hashvalue = (unkfile.group(3)) if str(hashvalue) in hashdata: monName = 'unknown' raidjson = hashdata[str(hashvalue)]["id"] count = hashdata[hashvalue]["count"] modify = hashdata[hashvalue]["modify"] raidHash_ = decodeHashJson(raidjson) gymid = raidHash_[0] lvl = raidHash_[1] mon = int(raidHash_[2]) monid = int(raidHash_[2]) mon = "%03d" % mon if mon == '000': type = 'egg' monPic = '' else: type = 'mon' monPic = '/asset/pokemon_icons/pokemon_icon_' + mon + '_00.png' if str(monid) in mondata: monName = i8ln(mondata[str(monid)]["name"]) eggId = eggIdsByLevel[int(lvl) - 1] if eggId == 1: eggPic = '/asset/static_assets/png/ic_raid_egg_normal.png' if eggId == 2: eggPic = '/asset/static_assets/png/ic_raid_egg_rare.png' if eggId == 3: eggPic = '/asset/static_assets/png/ic_raid_egg_legendary.png' creationdate = datetime.datetime.fromtimestamp(creation_date(file)).strftime('%Y-%m-%d %H:%M:%S') if conf_args.madmin_time == "12": creationdate = datetime.datetime.strptime(creationdate, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %I:%M:%S %p') modify = datetime.datetime.strptime(modify, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %I:%M:%S %p') name = 'unknown' lat = '0' lon = '0' url = '0' description = '' gymImage = 'ocr/gym_img/_' + str(gymid) + '_.jpg' if str(gymid) in data: name = data[str(gymid)]["name"].replace("\\", r"\\").replace('"', '') lat = data[str(gymid)]["latitude"] lon = data[str(gymid)]["longitude"] if data[str(gymid)]["description"]: description = data[str(gymid)]["description"].replace("\\", r"\\").replace('"', '').replace("\n", "") raidJson = ({'id': gymid, 'lat': lat, 'lon': lon, 'hashvalue': hashvalue, 'filename': file[4:], 'name': name, 'description': description, 'gymimage': gymImage, 'count': count, 'creation': creationdate, 'modify': modify, 'level': lvl, 'mon': mon, 'type': type, 'eggPic': eggPic, 'monPic': monPic, 'monname': monName }) raids.append(raidJson) else: log.debug("File: " + str(file) + " not found in Database") os.remove(str(file)) continue return jsonify(raids)
def rewarditem(itemid): file = open_json_file('items') return (file[str(itemid)]['name'])
def questtype(quest_type): file = open_json_file('types') return (file[str(quest_type)]['text'])
def questtask(typeid, condition, target): gettext.find('quest', 'locales', all=True) lang = gettext.translation('quest', localedir='locale', fallback=True) lang.install() pokemonTypes = open_json_file('pokemonTypes') items = open_json_file('items') throwTypes = {"10": _("Nice"), "11": _("Great"), "12": _("Excellent"), "13": _("Curveball")} arr = {} arr['0'] = target text = questtype(typeid) if typeid == 4: arr['wb'] = "" arr['type'] = "" arr['poke'] = "" text = _("Catch {0} {type}Pokemon{wb}.") match_object = re.search(r'"pokemon_type": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['type'] = pokemonTypes[pt[0]].title() + _('-type ') else: for ty in pt: arr['type'] += (_('or ') if last == cur else '') + \ pokemonTypes[ty].title() + (_('-type ') if last == cur else '-, ') cur += 1 if re.search(r"'type': 3", condition) is not None: arr['wb'] = _(" with weather boost") match_object = re.search(r'"pokemon_ids": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['poke'] = i8ln(pokemonname(pt[0])) else: for ty in pt: arr['poke'] += (_('or ') if last == cur else '') + \ i8ln(pokemonname(ty)) + ('' if last == cur else ', ') cur += 1 text = _('Catch {0} {poke}.') elif typeid == 5: text = _("Spin {0} Pokestops or Gyms.") if re.search(r'"type": 12', condition) is not None: text = _("Spin {0} never visited Pokestops or Gyms.") elif typeid == 6: text = _("Hatch {0} Eggs.") elif typeid == 7: if re.search(r'"type": 9', condition) is not None: text = _("Win {0} Gym Battles.") elif re.search(r'"type": 10', condition) is not None: text = _("Use a supereffective Charged Attack in {0} Gym battles.") else: text = _("Battle in a Gym {0} times.") elif typeid == 8: if re.search(r'"type": 6', condition) is not None: text = _("Win {0} Raids.") if re.search(r'"raid_level": \[3, 4, 5\]', condition) is not None: text = _('Win a level 3 or higher raid.') if re.search(r'"raid_level": \[2, 3, 4, 5\]', condition) is not None: text = _('Win a level 2 or higher raid.') else: text = _("Battle in {0} Raids.") elif typeid == 10: text = _("Transfer {0} Pokemon.") elif typeid == 11: test = _("Favourite {0} Pokemon.") elif typeid == 13: text = _('Use {0} {type}Berries to help catch Pokemon.') arr['type'] = "" match_object = re.search(r'"item": ([0-9]+)', condition) if match_object is not None: arr['type'] = items[match_object.group( 1)]['name'].replace(_(' Berry'), '')+" " elif typeid == 14: text = _('Power up Pokemon {0} times.') elif typeid == 15: text = _("Evolve {0} Pokemon.") # [{'type': 1, 'with_pokemon_type': {'pokemon_type': [12]}}] if re.search(r'"type": 11', condition) is not None: text = _("Use an item to evolve a Pokemon.") elif re.search(r'"type": 1', condition) is not None: text = _("Evolve {0} {type}Pokemon") arr['wb'] = "" arr['type'] = "" arr['poke'] = "" match_object = re.search( r'"pokemon_type": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['type'] = pokemonTypes[pt[0]].title() + _('-type ') else: for ty in pt: arr['type'] += (_('or ') if last == cur else '') + pokemonTypes[ty].title() + ( _('-type ') if last == cur else '-, ') cur += 1 elif re.search(r'"type": 2', condition) is not None: arr['wb'] = "" arr['type'] = "" arr['poke'] = "" match_object = re.search( r'"pokemon_ids": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['poke'] = i8ln(pokemonname(pt[0])) else: for ty in pt: arr['poke'] += (_('or ') if last == cur else '') + i8ln(pokemonname(ty)) + ( '' if last == cur else ', ') cur += 1 text = _('Evolve {0} {poke}.') elif typeid == 16: arr['inrow'] = "" arr['curve'] = "" arr['type'] = "" if re.search(r'"type": 14', condition) is not None: arr['inrow'] = _(" in a row") if re.search(r'"type": 15', condition) is not None: arr['curve'] = _("Curveball ") match_object = re.search(r'"throw_type": ([0-9]{2})', condition) if match_object is not None: arr['type'] = throwTypes[match_object.group(1)]+" " text = _("Make {0} {type}{curve}Throws{inrow}.") elif typeid == 17: text = _('Earn {0} Candies walking with your buddy.') elif typeid == 23: text = _('Trade {0} Pokemon.') elif typeid == 24: text = _('Send {0} gifts to friends.') if int(target) == int(1): text = text.replace(_(' Eggs'), _('n Egg')) text = text.replace(_(' Raids'), _(' Raid')) text = text.replace(_(' Battles'), _(' Battle')) text = text.replace(_(' candies'), _(' candy')) text = text.replace(_(' gifts'), _(' gift')) text = text.replace(_(' {0} times'), '') arr['0'] = _("a") for key, val in arr.items(): text = text.replace('{'+key+'}', str(val)) text = text.replace(' .', '.') text = text.replace(' ', ' ') return text
def pokemonname(id): file = open_json_file('pokemon') return file[str(int(id))]["name"]
def questtask(typeid, condition, target): gettext.find('quest', 'locales', all=True) lang = gettext.translation('quest', localedir='locale', fallback=True) lang.install() pokemonTypes = open_json_file('pokemonTypes') items = open_json_file('items') throwTypes = {"10": _("Nice"), "11": _("Great"), "12": _("Excellent"), "13": _("Curveball")} arr = {} arr['0'] = target text = questtype(typeid) if typeid == 4: arr['wb'] = "" arr['type'] = "" arr['poke'] = "" arr['different'] = "" text = _("Catch {0}{different} {type}Pokemon{wb}") match_object = re.search(r'"pokemon_type": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['type'] = pokemonTypes[pt[0]].title() + _('-type ') else: for ty in pt: arr['type'] += (_('or ') if last == cur else '') + \ pokemonTypes[ty].title() + (_('-type ') if last == cur else '-, ') cur += 1 if re.search(r'"type": 3', condition) is not None: arr['wb'] = _(" with weather boost") elif re.search(r'"type": 21', condition) is not None: arr['different'] = _(" different species of") match_object = re.search(r'"pokemon_ids": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['poke'] = i8ln(pokemonname(pt[0])) else: for ty in pt: arr['poke'] += (_('or ') if last == cur else '') + \ i8ln(pokemonname(ty)) + ('' if last == cur else ', ') cur += 1 text = _('Catch {0} {poke}') elif typeid == 5: text = _("Spin {0} Pokestops or Gyms") if re.search(r'"type": 12', condition) is not None: text = _("Spin {0} Pokestops you haven't visited before") elif typeid == 6: text = _("Hatch {0} Eggs") elif typeid == 7: if re.search(r'"type": 9', condition) is not None: text = _("Win {0} Gym Battles") elif re.search(r'"type": 10', condition) is not None: text = _("Use a supereffective Charged Attack in {0} Gym battles") else: text = _("Battle in a Gym {0} times") elif typeid == 8: if re.search(r'"type": 6', condition) is not None: text = _("Win {0} Raids") if re.search(r'"raid_level": \[3, 4, 5\]', condition) is not None: text = _('Win a level 3 or higher raid') if re.search(r'"raid_level": \[2, 3, 4, 5\]', condition) is not None: text = _('Win a level 2 or higher raid') else: text = _("Battle in {0} Raids") elif typeid == 10: text = _("Transfer {0} Pokemon") elif typeid == 11: text = _("Favourite {0} Pokemon") elif typeid == 13: text = _('Use {0} {type}Berries to help catch Pokemon') arr['type'] = "" match_object = re.search(r'"item": ([0-9]+)', condition) if match_object is not None: arr['type'] = items[match_object.group( 1)]['name'].replace(_(' Berry'), '')+" " elif typeid == 14: text = _('Power up Pokemon {0} times') elif typeid == 15: text = _("Evolve {0} Pokemon") if re.search(r'"type": 11', condition) is not None: text = _("Use an item to evolve a Pokemon") elif re.search(r'"type": 1', condition) is not None: text = _("Evolve {0} {type}Pokemon") arr['wb'] = "" arr['type'] = "" arr['poke'] = "" match_object = re.search( r'"pokemon_type": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['type'] = pokemonTypes[pt[0]].title() + _('-type ') else: for ty in pt: arr['type'] += (_('or ') if last == cur else '') + pokemonTypes[ty].title() + ( _('-type ') if last == cur else '-, ') cur += 1 elif re.search(r'"type": 2', condition) is not None: arr['wb'] = "" arr['type'] = "" arr['poke'] = "" match_object = re.search( r'"pokemon_ids": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['poke'] = i8ln(pokemonname(pt[0])) else: for ty in pt: arr['poke'] += (_('or ') if last == cur else '') + i8ln(pokemonname(ty)) + ( '' if last == cur else ', ') cur += 1 text = _('Evolve {0} {poke}') elif typeid == 16: arr['inrow'] = "" arr['curve'] = "" arr['type'] = "" if re.search(r'"type": 14', condition) is not None: arr['inrow'] = _(" in a row") if re.search(r'"type": 15', condition) is not None: arr['curve'] = _("Curveball ") match_object = re.search(r'"throw_type": ([0-9]{2})', condition) if match_object is not None: arr['type'] = throwTypes[match_object.group(1)]+" " text = _("Make {0} {type}{curve}Throws{inrow}") elif typeid == 17: text = _('Earn {0} Candies walking with your buddy') elif typeid == 22: if int(target) == int(1): text = _('Make a new friend') else: text = _('Make {0} new friends') elif typeid == 23: text = _('Trade {0} Pokemon') arr['distance'] = "" if re.search(r'"type": 25', condition) is not None: arr['distance'] = re.search(r'"distance_km": ([0-9, ]+)', condition).group(1) if int(target) == int(1): text = _('Trade Pokemon caught {distance} km apart') else: text = _('Trade {0} Pokemon caught {distance} km apart') elif typeid == 24: text = _('Send {0} gifts to friends') elif typeid == 27: # PVP against trainer or team leader. if re.search(r'"type": 22', condition) is not None: text = _('Battle a Team Leader {0} times') elif re.search(r'"type": 23', condition) is not None: text = _('Battle another Trainer {0} times') elif typeid == 28: # Take snapshots quest if re.search(r'"type": 28', condition) is not None: text = _("Take {0} snapshots of your Buddy") elif re.search(r'"type": 2', condition) is not None: arr['poke'] = "" match_object = re.search( r'"pokemon_ids": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['poke'] = i8ln(pokemonname(pt[0])) else: for ty in pt: arr['poke'] += (_('or ') if last == cur else '') + i8ln(pokemonname(ty)) + ( '' if last == cur else ', ') cur += 1 text = _("Take {0} snapshots of {poke}") elif re.search(r'"type": 1', condition) is not None: text = _("Take {0} snapshots of {type} Pokemon") arr['wb'] = "" arr['type'] = "" arr['poke'] = "" match_object = re.search( r'"pokemon_type": \[([0-9, ]+)\]', condition) if match_object is not None: pt = match_object.group(1).split(', ') last = len(pt) cur = 1 if last == 1: arr['type'] = pokemonTypes[pt[0]].title() + _('-type ') else: for ty in pt: arr['type'] += (_('or ') if last == cur else '') + pokemonTypes[ty].title() + ( _('-type ') if last == cur else '-, ') cur += 1 elif typeid == 29: # QUEST_BATTLE_TEAM_ROCKET Team Go rucket grunt batles. # Condition type 27 means against a grunt leader WITH_INVASION_CHARACTER if re.search(r'"type": 27', condition) is not None: text = _('Battle {0} times against the Team GO Rocket Leaders') elif int(target) == int(1): text = _('Battle against a Team Rocket Grunt') # Condition type 18 means win a battle if re.search(r'"type": 18', condition) is not None: text = text.replace(_('Battle'), _('Win')) if int(target) == int(1): text = text.replace(_(' Eggs'), _('n Egg')) text = text.replace(_(' Raids'), _(' Raid')) text = text.replace(_(' Battles'), _(' Battle')) text = text.replace(_(' candies'), _(' candy')) text = text.replace(_(' gifts'), _(' gift')) text = text.replace(_(' Pokestops'), _(' Pokestop')) text = text.replace(_(' {0} snapshots'), _(' a snapshot')) text = text.replace(_('Make {0} {type}{curve}Throws'), _('Make a {type}{curve}Throw')) text = text.replace(_(' {0} times'), '') text = text.replace(_('{0} hearts'), _('a heart')) arr['0'] = _("a") for key, val in arr.items(): text = text.replace('{'+key+'}', str(val)) text = text.replace(' ', ' ').strip() return text
def showmonsidpicker(self): edit = request.args.get('edit') type = request.args.get('type') header = "" title = "" if request.method == 'GET' and (not edit or not type): return render_template('showmonsidpicker.html', error_msg="How did you end up here? Missing params.", header=header, title=title) with open('configs/mappings.json') as f: mapping = json.load(f) if "areas" not in mapping: return render_template('showmonsidpicker.html', error_msg="No areas defined at all, please configure first.", header=header, title=title) this_area = None this_area_index = -1 for t_area in mapping["areas"]: this_area_index += 1 if t_area["name"] == edit and t_area["mode"] == type: this_area = t_area break if this_area == None: return render_template('showmonsidpicker.html', error_msg="No area (" + edit + " with mode: " + type + ") found in mappings, add it first.", header=header, title=title) title = "Mons ID Picker for " + edit header = "Editing area " + edit + " (" + type + ")" backurl = "config?type=" + type + "&area=areas&block=settings&edit=" + edit if "settings" not in this_area: return render_template('showmonsidpicker.html', error_msg="No settings key found for area " + edit + "(" + type + "). Configure it first.", header=header, title=title) if request.method == 'POST': new_mons_list = request.form.get('current_mons_list') if not new_mons_list: return redirect("/showsettings", code=302) mapping["areas"][this_area_index]["settings"]["mon_ids_iv"] = ast.literal_eval(new_mons_list) with open('configs/mappings.json', 'w') as outfile: json.dump(mapping, outfile, indent=4, sort_keys=True) return redirect(backurl, code=302) if "mon_ids_iv" not in this_area["settings"]: current_mons = [] else: current_mons = this_area["settings"]["mon_ids_iv"] mondata = open_json_file('pokemon') current_mons_list = [] for mon_id in current_mons: try: mon_name = i8ln(mondata[str(mon_id)]["name"]) except KeyError: mon_name = "No-name-in-file-please-fix" current_mons_list.append({"mon_name": mon_name, "mon_id": str(mon_id)}) # Why o.O stripped_mondata = {} for mon_id in mondata: stripped_mondata[mondata[str(mon_id)]["name"]] = mon_id if os.environ['LANGUAGE'] != "en": try: localized_name = i8ln(mondata[str(mon_id)]["name"]) stripped_mondata[localized_name] = mon_id except KeyError: pass formhiddeninput = '<form action="showmonsidpicker?edit=' + edit + '&type=' + type + '" id="showmonsidpicker" method="post">' formhiddeninput += '<input type="hidden" id="current_mons_list" name="current_mons_list" value="' + str( current_mons) + '">' formhiddeninput += '<button type="submit" class="btn btn-success">Save</button></form>' return render_template('showmonsidpicker.html', backurl=backurl, formhiddeninput=formhiddeninput, current_mons_list=current_mons_list, stripped_mondata=stripped_mondata, header=header, title=title)