gif-pokmon

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])
{'name': 'houndour', 'resource_uri': 'api/v1/pokemon/228/'}
In [37]:
allpok
Out[37]:
778
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
rattata
http://media1.giphy.com/media/vXkfATtZmC26Q/giphy.gif
http://media0.giphy.com/media/IrMkKlhZy4hri/giphy.gif
http://media4.giphy.com/media/jeWqeTeBS03WE/giphy.gif
http://media3.giphy.com/media/NN4fvJBKKvrnq/giphy.gif
http://media2.giphy.com/media/A3LyV2yV5r5cI/giphy.gif
http://media1.giphy.com/media/6obZXFnopj9vy/giphy.gif
http://media4.giphy.com/media/CZgC0EiQhwiM8/giphy.gif
http://media2.giphy.com/media/10oCqxckv42wlq/giphy.gif
http://media4.giphy.com/media/OZnzDqIzdduuY/giphy.gif
charmander
http://media2.giphy.com/media/PiiQ5B1XxxiX6/giphy.gif
http://media3.giphy.com/media/V4sY8JCTxGyaI/giphy.gif
http://media1.giphy.com/media/fJXClS1SskWPu/giphy.gif
http://media2.giphy.com/media/11agp3tD5MPgnC/giphy.gif
http://media2.giphy.com/media/hEpqDK5fSGeqc/giphy.gif
http://media2.giphy.com/media/6JvWR1rDbseeQ/giphy.gif
http://media0.giphy.com/media/EUge7PKTnkwzm/giphy.gif
http://media1.giphy.com/media/Lk3CyavFIcr2o/giphy.gif
http://media1.giphy.com/media/u1k1kpDZSw5sA/giphy.gif
http://media.giphy.com/media/YmAqCTTOLHh0A/giphy-tumblr.gif
http://media4.giphy.com/media/WJ7Tr9wi8xVe0/giphy.gif
http://media2.giphy.com/media/kyQZBTnF1fG2A/giphy.gif
http://media.giphy.com/media/3lttbqFYuaKsM/giphy-tumblr.gif
http://media1.giphy.com/media/d8erhw94dHRsI/giphy.gif
http://media.giphy.com/media/2Faz6MZP8J3zpcXBe/giphy-tumblr.gif
http://media2.giphy.com/media/zggFOBuDFySDm/giphy.gif
http://media3.giphy.com/media/7YmRxmyA3QA3C/giphy.gif
http://media4.giphy.com/media/vz5JEg2WIJ8hG/giphy.gif
http://media1.giphy.com/media/OTr3AVq8Pm2XK/giphy.gif
http://media3.giphy.com/media/C5BvJRoI0ONs4/giphy.gif
http://media2.giphy.com/media/4vGhTk9nDMnug/giphy.gif
http://media4.giphy.com/media/gdh0jRFilcn4Y/giphy.gif
http://media4.giphy.com/media/4MwcPSlM8j3IA/giphy.gif
http://media3.giphy.com/media/d4yP1krJcfdCM/giphy.gif
http://media4.giphy.com/media/bLiebL9q4RMK4/giphy.gif
charmeleon
http://media2.giphy.com/media/R0fZ5K1BspBjW/giphy.gif
http://media1.giphy.com/media/u1k1kpDZSw5sA/giphy.gif
http://media1.giphy.com/media/3r3bSqctriays/giphy.gif
http://media3.giphy.com/media/7YmRxmyA3QA3C/giphy.gif
http://media4.giphy.com/media/vz5JEg2WIJ8hG/giphy.gif
http://media3.giphy.com/media/C5BvJRoI0ONs4/giphy.gif
http://media1.giphy.com/media/OTr3AVq8Pm2XK/giphy.gif
http://media4.giphy.com/media/4FPCEiIGk41cQ/giphy.gif
http://media4.giphy.com/media/tyoOzh4nA1Fao/giphy.gif
http://media0.giphy.com/media/Gccz9v9BmGHtu/giphy.gif
http://media1.giphy.com/media/2LqbHgd5gwgO4/giphy.gif
http://media4.giphy.com/media/cYmRQxMLaK9gI/giphy.gif
http://media4.giphy.com/media/wCnNTsp817oY0/giphy.gif
http://media1.giphy.com/media/POGOvsLHgXmpi/giphy.gif
http://media1.giphy.com/media/OKG0r9IgZ11ba/giphy.gif
http://media2.giphy.com/media/oecPcKjruvytG/giphy.gif
http://media3.giphy.com/media/d4yP1krJcfdCM/giphy.gif
http://media4.giphy.com/media/bLiebL9q4RMK4/giphy.gif
http://media4.giphy.com/media/p25VnssgQTo4w/giphy.gif
http://media1.giphy.com/media/IlzWt9twEUeSQ/giphy.gif
http://media3.giphy.com/media/BM1w3GRjpTrk4/giphy.gif
http://media4.giphy.com/media/BRwmhn51DJh8A/giphy.gif
http://media3.giphy.com/media/DhIHKaOKB5pUA/giphy.gif
http://media4.giphy.com/media/nBHnyQePKnES4/giphy.gif
http://media3.giphy.com/media/tTsyn0reTC3rG/giphy.gif
wartortle
http://media3.giphy.com/media/APUf2KTVPMUo/giphy.gif
http://media3.giphy.com/media/13RuvX8oKp701G/giphy.gif
http://media1.giphy.com/media/EhTwMHUJMrc7m/giphy.gif
http://media2.giphy.com/media/MZpmFL1wqh60g/giphy.gif
http://media4.giphy.com/media/GVHKUACqw8480/giphy.gif
http://media3.giphy.com/media/cHmJaZS0vw4Ny/giphy.gif
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-43-1f5c2d9799f0> in <module>()
     10             response = requests.get((jswri['data'][jsw]['images']['downsized']['url']), stream=True)
     11             with open('/home/wcmckee/Downloads/gify/' + (pokload['pokemon'][alpo]['name']) + str(jsw) + '.gif', 'wb') as out_file:
---> 12                 shutil.copyfileobj(response.raw, out_file)
     13                 del response

/usr/lib/python3.4/shutil.py in copyfileobj(fsrc, fdst, length)
     64     """copy data from file-like object fsrc to file-like object fdst"""
     65     while 1:
---> 66         buf = fsrc.read(length)
     67         if not buf:
     68             break

/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/response.py in read(self, amt, decode_content, cache_content)
    172             else:
    173                 cache_content = False
--> 174                 data = self._fp.read(amt)
    175                 if amt != 0 and not data:  # Platform-specific: Buggy versions of Python.
    176                     # Close the connection when no data is returned

/usr/lib/python3.4/http/client.py in read(self, amt)
    498             # Amount is given, so call base class version
    499             # (which is implemented in terms of self.readinto)
--> 500             return super(HTTPResponse, self).read(amt)
    501         else:
    502             # Amount is not given (unbounded read) so we must check self.length

/usr/lib/python3.4/http/client.py in readinto(self, b)
    537         # connection, and the user is reading more bytes than will be provided
    538         # (for example, reading in 1k chunks)
--> 539         n = self.fp.readinto(b)
    540         if not n and b:
    541             # Ideally, we would raise IncompleteRead if the content-length

/usr/lib/python3.4/socket.py in readinto(self, b)
    369         while True:
    370             try:
--> 371                 return self._sock.recv_into(b)
    372             except timeout:
    373                 self._timeout_occurred = True

KeyboardInterrupt: 

Comments

Comments powered by Disqus