-
Notifications
You must be signed in to change notification settings - Fork 0
/
gif-pokmon.py
65 lines (36 loc) · 1.3 KB
/
gif-pokmon.py
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
# coding: utf-8
# gif pokmon
#
# script to explore the pokemon api and get gifs.
# In[42]:
import requests
import json
import shutil
# In[29]:
reqg = requests.get('http://pokeapi.co/api/v1/pokedex/1/')
# In[30]:
retxt = reqg.text
# In[31]:
pokload = json.loads(retxt)
# In[32]:
allpok = len(pokload['pokemon'])
# In[36]:
print(pokload['pokemon'][200])
# In[37]:
allpok
# In[ ]:
opwritj = requests.get('http://api.giphy.com/v1/gifs/search?q=' + (pokload['pokemon'][alpo]['name']) + '&api_key=dc6zaTOxFJmzC')
# In[43]:
for alpo in range(allpok):
print(pokload['pokemon'][alpo]['name'])
opwritj = requests.get('http://api.giphy.com/v1/gifs/search?q=' + (pokload['pokemon'][alpo]['name']) + '&api_key=dc6zaTOxFJmzC')
wrijrd = opwritj.text
jswri = json.loads(wrijrd)
jswln = len(jswri['data'])
for jsw in range(0, jswln):
if '.gif' in jswri['data'][jsw]['images']['downsized']['url']:
print(jswri['data'][jsw]['images']['downsized']['url'])
response = requests.get((jswri['data'][jsw]['images']['downsized']['url']), stream=True)
with open('/home/wcmckee/Downloads/gify/' + (pokload['pokemon'][alpo]['name']) + str(jsw) + '.gif', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response