-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.py
More file actions
69 lines (59 loc) · 1.6 KB
/
functions.py
File metadata and controls
69 lines (59 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import requests
import json
from pprint import pprint
def get_pokemon(tweet):
types = ""
birthday = obtain_date(tweet)
index = get_pokemon_index(birthday)
url = "https://pokeapi.co/api/v2/pokemon/"+ str(index)
resp = requests.get(url)
data = resp.json()
name = data['name'].capitalize()
for i in range(len(data['types'])):
type = data['types'][i]['type']['name']
type = type.capitalize()
types += type + " "
pokemon = {
'name': name,
'index': str(index),
'type': types,
'photo':data['sprites']['other']['official-artwork']['front_default'],
}
pic = requests.get(pokemon['photo'])
file = open("pokemon.png", "wb")
file.write(pic.content)
file.close()
return pokemon
#get get_pokemon_index, (month, day, year) and mod by 4
def get_pokemon_index(birthday):
x = (birthday) % 898
if x == 0:
x = x+1
return x
elif x != 0:
return x
def return_birthday(queue):
current_num = ""
num_arr = []
for i in range(len(queue)):
if(queue[i].isdigit()):
current_num += queue[i]
else:
num_arr.append(current_num)
current_num = ""
num_arr.append(current_num)
return num_arr
def obtain_date(s):
num_arr = []
queue = []
birthday = 0
for i in range(len(s)):
if(s[i].isdigit() or s[i] == '/'):
queue.append(s[i])
num_arr = return_birthday(queue)
for i in range(len(num_arr)):
num = int(num_arr[i])
birthday += num
return birthday
s = "3/15/2000"
get_pokemon(s)