Best Python code snippet using autotest_python
pokemon_entity.py
Source:pokemon_entity.py
...46 self.learned_moves = learned_moves47 self.dex_entry = dex_entry48 @classmethod49 def from_addr(cls, addr, internal_index) -> None:50 name = GBText(data.get_static_data(pokedata.POKEMON_NAME_POINTER+(pokedata.POKEMON_NAME_LENGTH*internal_index),pokedata.BYTE,pokedata.POKEMON_NAME_LENGTH))51 pokedex_num = data.get_static_data(addr,pokedata.BYTE,1).collapse()52 base_hp = data.get_static_data(addr+0x01,pokedata.BYTE,1).collapse()53 base_attack = data.get_static_data(addr+0x02,pokedata.BYTE,1).collapse()54 base_defense = data.get_static_data(addr+0x03,pokedata.BYTE,1).collapse()55 base_speed = data.get_static_data(addr+0x04,pokedata.BYTE,1).collapse()56 base_special = data.get_static_data(addr+0x05,pokedata.BYTE,1).collapse()57 type1 = data.get_static_data(addr+0x06,pokedata.BYTE,1).collapse()58 type2 = data.get_static_data(addr+0x07,pokedata.BYTE,1).collapse()59 catch_rate = data.get_static_data(addr+0x08,pokedata.BYTE,1).collapse()60 base_exp_yeild = data.get_static_data(addr+0x09,pokedata.BYTE,1).collapse()61 front_sprite = Sprite.parse_pkmn_sprite(Addr(bank=cls.__get_sprite_bank(internal_index),addr=data.get_static_data(addr+0x0B,pokedata.BYTE,2).collapse(rev=True)))62 back_sprite = Sprite.parse_pkmn_sprite(Addr(bank=cls.__get_sprite_bank(internal_index),addr=data.get_static_data(addr+0x0D,pokedata.BYTE,2).collapse(rev=True)))63 attacks_lvl_1 = data.get_static_data(addr+0x0F,pokedata.BYTE,4).collapse()64 growth_rate = data.get_static_data(addr+0x13,pokedata.BYTE,1).collapse()65 learned_moves = data.get_static_data(addr+0x14,pokedata.BYTE,7).collapse()66 dex_entry = PokedexEntry(Addr(0x10,pokedata.datamap['Pokedex Entry Loc'][internal_index]))67 return cls(addr, internal_index, pokedex_num, name, base_hp, base_attack, base_defense, base_speed, base_special, 68 type1, type2, catch_rate, base_exp_yeild, front_sprite, back_sprite, attacks_lvl_1, 69 growth_rate, learned_moves, dex_entry)70 def __str__(self) -> str:71 return f"{self.pokedex_num:03},{self.internal_index:03},{self.base_hp:03},{self.dex_entry}"72 @classmethod73 def __get_sprite_bank(cls, index) -> int:74 '''75 ; index < $1F: bank $9 ("Pics 1")76 ; $1F ⤠index < $4A: bank $A ("Pics 2")77 ; $4A ⤠index < $74: bank $B ("Pics 3")78 ; $74 ⤠index < $99: bank $C ("Pics 4")79 ; $99 ⤠index: bank $D ("Pics 5")80 '''81 if index == 0x14:82 return 0x0183 elif index < 0x1F:84 return 0x0985 elif index < 0x4A:86 return 0x0A87 elif index < 0x74:88 return 0x0B89 elif index < 0x99:90 return 0x0C91 else:92 return 0x0D93 def to_json(self) -> dict:94 return {95 'index': self.internal_index,96 'pokedex': self.pokedex_num,97 'name': str(self.name),98 'base_stats':{99 'hp': self.base_hp,100 'attack': self.base_attack,101 'defense': self.base_defense,102 'speed': self.base_speed,103 'special': self.base_special,104 },105 'types': [106 self.type1,107 self.type2108 ],109 'catch_rate': self.catch_rate,110 'base_exp_yeild': self.base_exp_yeild,111 'front_sprite': self.front_sprite.to_json(),112 'back_sprite': self.back_sprite.to_json(),113 'attacks_lvl_1': self.attacks_lvl_1,114 'growth_rate': self.growth_rate,115 'learnable_moves': self.learned_moves,116 'pokedex_entry': self.dex_entry.to_json()117 }118class PokedexEntry:119 '''120 ; string: species name121 ; height in feet, inches122 ; weight in pounds123 ; text entry124 '''125 def __init__(self, addr) -> None:126 self.addr = addr127 self.species = GBText(data.get_var_data(addr,pokedata.BYTE,f"0x{GBText.STRING_END:#02x}"))128 h_feet_pkt = data.get_static_data(addr+len(self.species.packet.data),8,1)129 h_inches_pkt = data.get_static_data(h_feet_pkt.addr+len(h_feet_pkt.data),8,1)130 weight_pkt = data.get_static_data(h_inches_pkt.addr+len(h_inches_pkt.data),pokedata.BYTE,2)131 self.height = [h_feet_pkt.collapse(), h_inches_pkt.collapse()]132 self.weight = weight_pkt.collapse(rev=True)133 text_addr = data.get_static_data(weight_pkt.addr+len(weight_pkt.data)+1,pokedata.BYTE,2)134 text_bank = data.get_static_data(text_addr.addr+len(text_addr.data),pokedata.BYTE,1)135 if (Addr(bank=text_bank.collapse(),addr=text_addr.collapse(rev=True))<pokedata.END_FILE):136 self.text = GBText(data.get_var_data(Addr(bank=text_bank.collapse(),addr=text_addr.collapse(rev=True)),pokedata.BYTE,f"0x{GBText.STRING_END:#02x}"))137 else:138 self.text = "MISSING No. does>not exist.^Please look elsewere}"139 def __str__(self) -> str:140 height_str = f"{self.height[0]}' " + f'{self.height[1]}"'141 weight_str = f"{self.weight}lbs."142 return f"{{{self.addr} {str(self.species):<12} {height_str:<9} {weight_str:<10} {self.text}"143 def to_json(self) -> dict:...
fpl_api_handler.py
Source:fpl_api_handler.py
...4 Get data from the FPL API.5 """6 response = requests.get(url)7 return response.json()8def get_static_data(key):9 """10 Get requested data key from bootstrap-static endpoint11 Useful keys:12 - teams13 - events (GW overview for FPL)14 - elements (players)15 - element_types (player types)16 - elements_stats (map of player stats labels and column names)17 """18 URL = "https://fantasy.premierleague.com/api/bootstrap-static/"19 data = get_json_data(URL)20 21 #Keeping data till current GW (might have to change to get data only for current GW)22 if key == "events":23 data["events"] = [event for event in data["events"] if event["is_current"] == True or event["finished"] == True]24 return data[key]25def get_fixtures():26 """27 Get all upcoming fixtures from the fixtures endpoint28 """29 URL = "https://fantasy.premierleague.com/api/fixtures/"30 data = get_json_data(URL)31 data = [fixture for fixture in data if fixture['event'] != None]32 for fixture in data:33 keys = fixture.keys()34 keys_to_remove = set(keys) - set(["team_h", "team_a", "event", "id", "team_h_difficulty", "team_a_difficulty"])35 for key in keys_to_remove:36 fixture.pop(key)37 return data38def get_player_info(element_id, key):39 """40 Get player history from the element-summary endpoint41 Possible keys:42 - history43 - fixtures44 """45 URL = f"https://fantasy.premierleague.com/api/element-summary/{element_id}/"46 data = get_json_data(URL)47 data = data[key]48 return data49def get_manager_squad(manager_id, gw):50 """51 Get manager squad for a given gameweek52 """53 URL = f"https://fantasy.premierleague.com/api/entry/{manager_id}/event/{gw}/picks/"54 data = get_json_data(URL)55 data = data["picks"]56 return data57def get_manager_info(manager_id):58 """59 Get info for a praticular manager from the entry endpoint60 """61 URL = f"https://fantasy.premierleague.com/api/entry/{manager_id}/"62 data = get_json_data(URL)63 data.pop("leagues")64 65 return data66if __name__ == "__main__":67 #Running tests68 import json69 print(json.dumps(get_static_data("events")[1], indent=4, sort_keys=True))70 print(json.dumps(get_static_data("teams")[1], indent=4, sort_keys=True))71 print(json.dumps(get_static_data("elements")[1], indent=4, sort_keys=True))72 print(json.dumps(get_static_data("element_types")[1], indent=4, sort_keys=True))73 print(json.dumps(get_static_data("element_stats")[1], indent=4, sort_keys=True))74 print(json.dumps(get_fixtures()[1], indent=4, sort_keys=True))75 print(json.dumps(get_player_info(1, "history")[1], indent=4, sort_keys=True))76 print(json.dumps(get_player_info(1, "fixtures")[1], indent=4, sort_keys=True))77 print(json.dumps(get_manager_squad(1, 1)[1], indent=4, sort_keys=True))78 print(json.dumps(get_manager_info(1), indent=4, sort_keys=True))...
noaa_api.py
Source:noaa_api.py
...27 start=START,28 end=END)29 response = requests.get(url)30 return response.json()31def get_static_data():32 if os.path.exists(STATIC_WEATHER):33 with open(STATIC_WEATHER, 'r') as f:34 reader = csv.DictReader(f)35 data = list(reader)36 return data37def max_date(data_list):38 return max([sublist['DATE'] for sublist in data_list])39def add_one_day(date):40 if isinstance(date, str):41 date = datetime.datetime.strptime(date, STR_FORMAT)42 date += datetime.timedelta(1)43 return date.strftime(STR_FORMAT)44def append_data(response):45 first_time = not os.path.exists(STATIC_WEATHER)46 with open(STATIC_WEATHER, 'a', newline='') as f:47 fieldnames = response[0].keys()48 writer = csv.DictWriter(f, fieldnames)49 if first_time:50 writer.writeheader()51 writer.writerows(response.json())52def get_data(update_weather=False):53 data = get_static_data()54 if update_weather:55 latest_date = max_date(data)56 if latest_date >= END:57 return data58 else:59 global START60 if latest_date: # in case latest_date == None61 START = add_one_day(latest_date)62 call_api()63 data = get_static_data()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!