gifey

Downloads gifs based on a keyword from gifphy to a folder and serve them via a web server.

Find keywords from where?

Creative Commons Keywords - add the gif back into the posts.

Intergrate Nikola. Start saving the gif files in galleries folder. Why doesn't galleries folder render gif files?

Create nikola post that has the title (keyword) and post contents is the gif url (galleries - keyword)


In [1]:
import os

In [2]:
import requests
import json
import shutil
import dominate
from time import gmtime, strftime

import getpass

from walkdir import filtered_walk, dir_paths, all_paths, file_paths

In [3]:
getusr = getpass.getuser()

In [4]:
getusr


Out[4]:
'wcm'

In [17]:
keyword = input('Keyword: ')


Keyword: draw

In [18]:
gifydir = ('/home/{}/gify/'.format(getusr))

In [19]:
gifdi = os.listdir('/home/{}/gify/posts'.format(getusr))

In [20]:
keywddir = ('/home/{}/gify/galleries/{}'.format(getusr, keyword))

In [21]:
if os.path.isdir(keywddir) == True:
    print ('its true')
else:
    print ('its false')
    os.mkdir(keywddir)


its false

In [22]:
opwritj = requests.get('http://api.giphy.com/v1/gifs/search?q={}&api_key=dc6zaTOxFJmzC'.format(keyword))

In [23]:
wrijrd = opwritj.text

In [24]:
jswri = json.loads(wrijrd)

In [25]:
jswln = len(jswri['data'])

In [26]:
jswln


Out[26]:
25

In [27]:
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(keywddir + '/' + str(jsw) + '.gif', 'wb') as out_file:
            shutil.copyfileobj(response.raw, out_file)
            del response


http://media2.giphy.com/media/xTiTnM6WqhU5bcOxXy/giphy.gif
https://media.giphy.com/media/cL9XcvBhRSEpi/giphy-tumblr.gif
https://media3.giphy.com/media/Xicr2vn680efC/giphy.gif
https://media2.giphy.com/media/nRvbWvACVHu6s/giphy.gif
https://media.giphy.com/media/10hUAQhlpEklSo/giphy-tumblr.gif
https://media4.giphy.com/media/rZZSuYLPitqRG/giphy.gif
http://media4.giphy.com/media/l46ChKeGsmsfE3Un6/giphy.gif
https://media.giphy.com/media/EzXt0Iv86u3bq/giphy-tumblr.gif
https://media0.giphy.com/media/12rsZFouPvPdKM/giphy.gif
https://media3.giphy.com/media/btgxRPSVLSqHe/giphy.gif
https://media1.giphy.com/media/cwYFxCHok1YcM/giphy.gif
https://media3.giphy.com/media/TgKn0RoeGzha8/giphy.gif
https://media.giphy.com/media/AMIDkjWJtF1gQ/giphy-tumblr.gif
https://media4.giphy.com/media/dOkXDOIpHgECs/giphy.gif
https://media2.giphy.com/media/6pVlDiwR4DSw0/giphy.gif
https://media3.giphy.com/media/10ahySUoRTBwR2/giphy.gif
https://media.giphy.com/media/nIMSRivhg5woU/giphy-tumblr.gif
https://media4.giphy.com/media/lg5L8dh5ZwJ9K/giphy.gif
https://media.giphy.com/media/kkFCSOW2sAuDS/giphy-tumblr.gif
https://media.giphy.com/media/eWYJ9zDY2DJzG/giphy-tumblr.gif
https://media2.giphy.com/media/ekgxVjoTyi13i/giphy.gif
http://media.giphy.com/media/t1DyjJmSZwESY/giphy-tumblr.gif
https://media.giphy.com/media/yWR98zWGXwSju/giphy-tumblr.gif
https://media.giphy.com/media/rcZ6WfnvXSaD6/giphy-tumblr.gif
https://media.giphy.com/media/gCkszc7lKaCQw/giphy-tumblr.gif

In [28]:
os.chdir(gifydir)

In [29]:
os.system('nikola build')


Out[29]:
0

In [ ]: