コード例 #1
0
ファイル: basic.py プロジェクト: wwlodar/pokemon-app
def poke_name():
    pname = request.args.get('pname').lower()
    response = requests.get('https://pokeapi.co/api/v2/pokemon/' + str(pname))
    if response.status_code == 200 and len(pname) != 0:
        response = response.json()
        chosen_pokemon = Pokemon(pname)
        return render_template('pokemon.html', pname=pname, chosen_pokemon=chosen_pokemon)
    elif response.status_code == 200 and len(pname) == 0:
        return render_template('home.html')
    else:
        return render_template('error.html', pname=pname)
コード例 #2
0
 def build_pokedex(self):
     info = {"name": None, "poke_id": None, "type": None, "info": None}
     self.file = self.file.split("\n")
     poke_id = 1
     for line in self.file:
         if line.strip() == "":
             continue
         key, value = line.split(":")
         key = key.strip()
         value = value.strip()
         info[key] = value
         pokemon = Pokemon().new_from_file(info)
         self.pokedex[poke_id] = pokemon
         poke_id += 1
コード例 #3
0
grimer_attacks = [acid, feint_attack, tackle, scratch]
raticate_attacks = [slash, feint_attack, tackle, scratch]

# Pokemon attack list
charizard_attacks = [flamethrower, wing_attack, slash, fire_blast]
blastoise_attacks = [hydro_pump, waterfall, rapid_spin, crunch]
venusaur_attacks = [solar_beam, sludge_bomb, acid, giga_drain]
alakazam_attacks = [confusion, psybeam, tri_attack, flamethrower]
snorlax_attacks = [hyperbeam, mega_punch, ice_punch, crunch]
gyarados_attacks = [hydro_pump, waterfall, drill_peck, crunch]
machamp_attacks = [high_jump_kick, mega_punch, pay_back, ice_punch]
electabuzz_attacks = [thunder, thunder_bolt, slash, play_rough]
pidgeot_attacks = [wing_attack, drill_peck, slash, fly]

# Enemy Pokemon
persian = Pokemon("Persian", 130, 130, persian_attacks)
mewtwo = Pokemon("Mewtwo", 150, 140, mewtwo_attacks)
koffing = Pokemon("Koffing", 120, 120, koffing_attacks)
houndoom = Pokemon("Houndoom", 130, 130, houndoom_attacks)
murkrow = Pokemon("Murkrow", 120, 120, murkrow_attacks)
arbok = Pokemon("Arbok", 130, 130, arbok_attacks)
grimer = Pokemon("Grimer", 110, 110, grimer_attacks)
raticate = Pokemon("Raticate", 120, 120, raticate_attacks)

# User Pokemon
charizard = Pokemon("Charizard", 110, 110, charizard_attacks)
blastoise = Pokemon("Blastoise", 125, 125, blastoise_attacks)
venusaur = Pokemon("Venusaur", 125, 125, venusaur_attacks)
alakazam = Pokemon("Alakazam", 110, 110, alakazam_attacks)
snorlax = Pokemon("Snorlax", 170, 170, snorlax_attacks)
gyarados = Pokemon("Gyarados", 120, 120, gyarados_attacks)
コード例 #4
0
def pokemondata():
    cj = cookielib.CookieJar()
    #seesion=requests.Session();
    #headers={"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit 537/36 (KHTML, like Gecko) Chrome",
    #         "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)
    #创建Pokemon对象
    pokemon = []
    pokemon_r = []
    if (os.path.exists('pokemon.csv')):
        csv_file = codecs.open('pokemon.csv', 'r', "utf-8-sig")
        for stu in csv_file:
            tm = stu.split(',')
            poke = Pokemon(int(tm[0]), str(tm[1].encode('utf-8')),
                           str(tm[2].encode('utf-8')))
            attri_t = re.split('[/]', tm[12][1:])
            texing_t = re.split('[/]', tm[13][1:])
            poke.ADD(str(tm[3].encode('utf-8')), int(tm[4]), int(tm[5]),
                     int(tm[6]), int(tm[7]), int(tm[8]), int(tm[9]),
                     int(tm[10]), float(tm[11]), attri_t, texing_t,
                     str(tm[14].encode('utf-8')))
            pokemon.append(poke)
        pokemon_r = pokemon
    else:
        url = "http://www.pokemon.name/wiki/%E4%B8%BB%E9%A2%98:%E5%AE%9D%E5%8F%AF%E6%A2%A6"
        #创建Request对象
        #q=session.get(url,headers=headers);
        request = urllib2.Request(url)

        request.add_header("User-Agent", "Mozilla/5.0")
        response = urllib2.urlopen(request)
        soup = bf(response.read(), 'html.parser', from_encoding='utf-8')
        #	soup=bf(req.text);
        ccs = soup.find_all('td')
        for cc in ccs:
            links = cc.find_all('li')
            for link in links:
                if (len(link.get_text().split('. ')) == 2):
                    H = link.find('a')
                    Root = "http://www.pokemon.name"
                    poke = Pokemon(
                        int(link.get_text().split('. ')[0].split()[0].encode(
                            'utf-8')),
                        link.get_text().split('. ')[1].encode('utf-8'),
                        (Root.decode('utf-8') + H['href']).encode('utf-8'))
                    m = get_attri.get_attri(
                        poke.href, user_agent_list[int(
                            math.floor(len(user_agent_list) *
                                       random.random()))])
                    print poke.name, poke.array, time.localtime(time.time())
                    time.sleep(0.5 * random.random())
                    poke.ADD(m[-1], m[0], m[1], m[2], m[3], m[4], m[5], m[6],
                             m[7], m[8], m[9], m[10])
                    pokemon.append(poke)
        csvFile = open("pokemon.csv", 'w+')
        try:
            csvFile.write(codecs.BOM_UTF8)
            writer = csv.writer(csvFile)
            for i in pokemon:
                for j in range(len(i.leixing)):
                    attri_t = ""
                    for temp in i.attri[j]:
                        attri_t = attri_t + "/" + str(temp)
                    texing_t = ""
                    for temp in i.texing[j]:
                        texing_t = texing_t + "/" + str(temp)
                    writer.writerow(
                        (i.array, i.name, i.href, i.leixing[j], int(i.HP[j]),
                         int(i.Attack[j]), int(i.SPA[j]), int(i.Defense[j]),
                         int(i.SPD[j]), int(i.Speed[j]), int(i.TTL[j]),
                         float(i.Weight[j]), attri_t, texing_t, i.hide[j]))
                    pokemon_ = Pokemon(i.array, i.name, i.href)
                    pokemon_.ADD(i.leixing[j], int(i.HP[j]), int(i.Attack[j]),
                                 int(i.SPA[j]), int(i.Defense[j]),
                                 int(i.SPD[j]), int(i.Speed[j]), int(i.TTL[j]),
                                 float(i.Weight[j]), i.attri[j], i.texing[j],
                                 i.hide[j])
                    pokemon_r.append(pokemon_)

        finally:
            csvFile.close()
    return pokemon_r
コード例 #5
0
from pokedex_class import Pokedex
from pokemon_class import Pokemon

pokedex = Pokedex().return_pokedex()

# you've encountered a rattatta! ta. tata.

this_pokemon = Pokemon().new_from_dex(pokedex[2])
print(this_pokemon.name)
コード例 #6
0
# IMPORT

from pokemon_class import Pokemon
from trainer_class import Trainer

# INSTANTIATION

squirtle = Pokemon("Squirtle", 5, "Water", True)
charmander = Pokemon("Charmander", 5, "Fire", True)
sharmander = Pokemon("Sharmander", 5, "Fire", True)
bulbasaur = Pokemon("Bulbasaur", 5, "Grass", True)
bulbastrur = Pokemon("Bulbastrur", 5, "Grass", True)
bulbretasaur = Pokemon("Bulbretasaur", 5, "Grass", True)
butretrelbasaur = Pokemon("Butretrelbasaur", 5, "Grass", True)

antoine = Trainer("Antoine", 3)
bastien = Trainer("Bastien", 3)

bastien.add_pokelist(squirtle)
antoine.add_pokelist(charmander)
antoine.add_pokelist(sharmander)
antoine.add_pokelist(bulbasaur)
antoine.add_pokelist(bulbastrur)
antoine.add_pokelist(bulbretasaur)
antoine.add_pokelist(butretrelbasaur)

antoine.attack_trainer(bastien)
#squirtle.attack(charmander)
#squirtle.attack(charmander)
#squirtle.attack(charmander)
#squirtle.attack(charmander)
コード例 #7
0
from player_class import Player
from pokemon_class import Pokemon

b = Player('', '')
p = Pokemon()

b.ask_for_name()
#b.load_previous_player()

#p.save_pokemon()