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: 

nzpostaddy

nzpostaddy

yay maps, something I haven't really used before. Good to try something new.

Using some demo examples from nz post. Examples are printed below.

script to search for addresses.

Gets address from nzpost then displays static map from mapquestapi

In [1]:
import json
import shutil
import requests
In [2]:
opjsres = open('/home/wcmckee/github/nzpostad.json', 'r')
In [3]:
opjrd = opjsres.read()
In [4]:
nzpod = json.loads(opjrd)
In [5]:
nzpod
Out[5]:
{'addresses': [{'address_id': '196111',
   'dpid': '754977',
   'full_address': '19 Queen Alexandra Street, Lansdowne, Masterton 5810'},
  {'address_id': '197147',
   'dpid': '750361',
   'full_address': '23 Queen Alexandra Street, Lansdowne, Masterton 5810'},
  {'address_id': '195925',
   'dpid': '751485',
   'full_address': '7A Queen Alexandra Street, Lansdowne, Masterton 5810'},
  {'address_id': '198893',
   'dpid': '747422',
   'full_address': '8 Queen Alexandra Street, Lansdowne, Masterton 5810'},
  {'address_id': '195986',
   'dpid': '754969',
   'full_address': '9A Queen Alexandra Street, Lansdowne, Masterton 5810'}],
 'success': True}
In [6]:
nzpaddy = nzpod['addresses']
In [7]:
nzplen = len(nzpod['addresses'])
In [8]:
nzplen
Out[8]:
5
In [9]:
for nzp in range(0, nzplen):
    nzitm = (nzpaddy[nzp])
    print(nzitm['full_address'])
19 Queen Alexandra Street, Lansdowne, Masterton 5810
23 Queen Alexandra Street, Lansdowne, Masterton 5810
7A Queen Alexandra Street, Lansdowne, Masterton 5810
8 Queen Alexandra Street, Lansdowne, Masterton 5810
9A Queen Alexandra Street, Lansdowne, Masterton 5810
In [10]:
opsuccessad = open('/home/wcmckee/github/nzpostsuccess.json', 'r')
In [11]:
opsucrd = opsuccessad.read()
In [12]:
opjslo = json.loads(opsucrd)
In [13]:
opjslo
Out[13]:
{'address': {'city': 'Dunedin',
  'country': 'New Zealand',
  'depot_name': 'Dunedin Depot',
  'is_rural_delivery': False,
  'latitude': -45.9041,
  'longitude': 170.552,
  'postcode': '9013',
  'run_number': 'DCP025  ',
  'street': 'Oregon',
  'street_number': 71,
  'street_type': 'Street',
  'suburb': 'Ocean Grove'},
 'message_id': '618a5799-85e3-4559-8a62-280f231a26b3',
 'success': True}
In [14]:
opja = opjslo['address']
In [15]:
opja
Out[15]:
{'city': 'Dunedin',
 'country': 'New Zealand',
 'depot_name': 'Dunedin Depot',
 'is_rural_delivery': False,
 'latitude': -45.9041,
 'longitude': 170.552,
 'postcode': '9013',
 'run_number': 'DCP025  ',
 'street': 'Oregon',
 'street_number': 71,
 'street_type': 'Street',
 'suburb': 'Ocean Grove'}
In [16]:
latad = opja['latitude']
In [17]:
longad = opja['longitude']
In [18]:
latad
Out[18]:
-45.9041
In [19]:
longad
Out[19]:
170.552
In [ ]:
mapk = open('/home/wcmckee/github/mapkey.txt', 'r')
In [ ]:
mapkrd = mapk.read()
In [ ]:
reqimg = 'http://www.mapquestapi.com/staticmap/v4/getmap?key=' + mapkrd + '&size=400,200&zoom=10&center=' + str(latad) + ',' + str(longad) 
In [ ]:
rmnz = reqimg.replace('\n', '')
In [ ]:
response = requests.get(rmnz, stream=True)
with open('img.png', 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)
del response