GetsDrawn DotCom

This is a python script to generate the website GetsDrawn. It takes data from /r/RedditGetsDrawn and makes something awesome.

The script has envolved and been rewritten several times.

The first script for rgdsnatch was written after I got banned from posting my artwork on /r/RedditGetsDrawn. The plan was to create a new site that displayed stuff from /r/RedditGetsDrawn.

Currently it only displays the most recent 25 items on redditgetsdrawn.

This is moving forward from rgdsnatch.py because I am stuck on it.

TODO

Fix the links that don't link to png/jpeg and link to webaddress. Needs to get the images that are at that web address and embed them.

Display artwork submitted under the images.

Upload artwork to user. Sends them a message on redditgetsdrawn with links.

More pandas

Currently saves username-line-bw-colour.png to imgs folder. Instead get it to save to imgs/year/month/day/usernames.png. Script checks the year/month/day and if folder isnt created, it creates it. If folder is there, exit. Maybe get the reference image and save it with the line/bw/color.pngs


In [44]:
import os 
import requests
from bs4 import BeautifulSoup
import re
import json
import time
import praw
import dominate
from dominate.tags import * 
from time import gmtime, strftime
#import nose
#import unittest
import numpy as np
import pandas as pd
from pandas import *
from PIL import Image
from pprint import pprint
#import pyttsx
import shutil

In [45]:
gtsdrndir = ('/home/wcmckee/getsdrawndotcom')

In [46]:
os.chdir(gtsdrndir)

In [47]:
r = praw.Reddit(user_agent='getsdrawndotcom')

In [48]:
#getmin = r.get_redditor('itwillbemine')

In [49]:
#mincom = getmin.get_comments()

In [50]:
#engine = pyttsx.init()

#engine.say('The quick brown fox jumped over the lazy dog.')
#engine.runAndWait()

In [51]:
#shtweet = []

In [52]:
#for mi in mincom:
#    print mi
#    shtweet.append(mi)

In [53]:
bodycom = []
bodyicv = dict()

In [54]:
#beginz = pyttsx.init()

In [55]:
#for shtz in shtweet:
#    print shtz.downs
#    print shtz.ups
#    print shtz.body
#    print shtz.replies
    #beginz.say(shtz.author)
    #beginz.say(shtz.body)
    #beginz.runAndWait()
    
#    bodycom.append(shtz.body)
    #bodyic

In [56]:
#bodycom

In [57]:
getnewr = r.get_subreddit('redditgetsdrawn')

In [58]:
rdnew = getnewr.get_new()

In [59]:
lisrgc = []
lisauth = []

In [60]:
for uz in rdnew:
    #print uz
    lisrgc.append(uz)

In [61]:
gtdrndic = dict()

In [62]:
imgdir = ('/home/wcmckee/getsdrawndotcom/imgs')

In [20]:
artlist = os.listdir(imgdir)

In [21]:
from time import time

In [22]:
yearz = strftime("%y", gmtime())
monthz = strftime("%m", gmtime())
dayz = strftime("%d", gmtime())


#strftime("%y %m %d", gmtime())

In [79]:
imgzdir = ('/home/wcmckee/getsdrawndotcom/imgs/')
yrzpat = (imgzdir + yearz)
monzpath = (yrzpat + '/' + monthz)
dayzpath = (monzpath + '/' + dayz)
rmgzdays = (dayzpath + '/reference')
imgzdays = (dayzpath + '/art')

In [80]:
def ospacheck():
    if os.path.isdir(imgzdir + yearz) == True:
        print 'its true'
    else:
        print 'its false'
        os.mkdir(imgzdir + yearz)

In [81]:
ospacheck()


its true

In [65]:
#if os.path.isdir(imgzdir + yearz) == True:
#    print 'its true'
#else:
#    print 'its false'
#    os.mkdir(imgzdir + yearz)

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

#os.mkdir(monzpath)


its true

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

#os.mkdir(dayzpath)


its true

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


its false

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


its false

In [87]:
#artlist

In [88]:
httpad = ('http://getsdrawn.com/imgs')

In [89]:
#im = Image.new("RGB", (512, 512), "white")
#im.save(file + ".thumbnail", "JPEG")

In [90]:
for lisr in lisrgc:
    gtdrndic.update({'title': lisr.title})
    lisauth.append(str(lisr.author))

In [ ]:
rmgzdays = (dayzpath + '/reference')
imgzdays = (dayzpath + '/art')

In [91]:
os.chdir(imgzdays)

In [95]:
imgzdays


Out[95]:
'/home/wcmckee/getsdrawndotcom/imgs/14/12/20/art'

In [93]:
#os.listdir(dayzpath)

In [94]:
for lisa in lisauth:
    #print lisa + '-line.png'
    im = Image.new("RGB", (512, 512), "white")
    im.save(lisa + '-line.png')
    im = Image.new("RGB", (512, 512), "white")
    im.save(lisa + '-bw.png')

    #print lisa + '-bw.png'
    im = Image.new("RGB", (512, 512), "white")
    im.save(lisa + '-colour.png')

    #print lisa + '-colour.png'

In [75]:
os.listdir('/home/wcmckee/getsdrawndotcom/imgs')


Out[75]:
['ravensymoneislife-line.png',
 'RunOttawa613-bw.png',
 'fuzz_e_bear-colour.png',
 'fuzz_e_bear-bw.png',
 'iloveariiii-line.png',
 'plainclotheswoman-bw.png',
 'alikonagurl83-line.png',
 'starienite-colour.png',
 'neszero-line.png',
 'OrangeCloud-line.png',
 'JEWPACOLYPSE-line.png',
 'OhGollyG-line.png',
 'JoisofLife-bw.png',
 'alikonagurl83-colour.png',
 'DemTurtlesCom-line.png',
 'ravensymoneislife-bw.png',
 'sirenmika-bw.png',
 'lordneojoker-bw.png',
 'Quackattackaggie-bw.png',
 'youwinabagel-line.png',
 'iloveariiii-bw.png',
 'THORGNASH-bw.png',
 'Salerno1717-bw.png',
 'shripityshripit-bw.png',
 'ofalco-colour.png',
 'youwinabagel-colour.png',
 'Imbie81-colour.png',
 'Se7enOne-line.png',
 'youwinabagel-bw.png',
 'JEWPACOLYPSE-colour.png',
 'seahorseVT-bw.png',
 'celest123-line.png',
 'The_Beaner-bw.png',
 'arequest554-line.png',
 'MrsEvil-bw.png',
 'GymIsFun-bw.png',
 'TD2705-colour.png',
 'iamwolf777-line.png',
 'RunOttawa613-colour.png',
 'uhhhname-bw.png',
 'RunOttawa613-line.png',
 'sirenmika-colour.png',
 'ghoztcum-line.png',
 'labatomi-bw.png',
 'OhGollyG-colour.png',
 'lordneojoker-colour.png',
 'shripityshripit-line.png',
 'GymIsFun-line.png',
 'BonAnchovy-bw.png',
 'labatomi-line.png',
 'ofalco-line.png',
 'neszero-bw.png',
 'BonAnchovy-colour.png',
 'THORGNASH-line.png',
 'Mailing_a_Bear-colour.png',
 'REALchampagnePAPI-colour.png',
 'REALchampagnePAPI-bw.png',
 'JEWPACOLYPSE-bw.png',
 'bulgarianutter-colour.png',
 'plainclotheswoman-colour.png',
 'GymIsFun-colour.png',
 'LongDistanceGuyy-line.png',
 'CapDance-bw.png',
 'iloveariiii-colour.png',
 'ravensymoneislife-colour.png',
 'OhLydia-colour.png',
 'OrangeCloud-bw.png',
 'crayolalightblue-bw.png',
 '_jazmin-bw.png',
 'DemTurtlesCom-bw.png',
 'BeyondMars-colour.png',
 'crayolalightblue-colour.png',
 'uhhhname-line.png',
 'The_Beaner-line.png',
 'MrsEvil-line.png',
 'crayolalightblue-line.png',
 'CapDance-colour.png',
 'JoisofLife-colour.png',
 'BeyondMars-bw.png',
 'Mailing_a_Bear-bw.png',
 'THORGNASH-colour.png',
 'MrsEvil-colour.png',
 'iamwolf777-bw.png',
 '14',
 'ofalco-bw.png',
 'jerrytt-bw.png',
 'OhGollyG-bw.png',
 'Imbie81-bw.png',
 'fuzz_e_bear-line.png',
 'arequest554-bw.png',
 'Se7enOne-colour.png',
 'iamwolf777-colour.png',
 '12',
 'Quackattackaggie-line.png',
 'Jasperthecat77-bw.png',
 'OhLydia-bw.png',
 'Se7enOne-bw.png',
 'sirenmika-line.png',
 'lordneojoker-line.png',
 'LongDistanceGuyy-colour.png',
 'jerrytt-colour.png',
 'Dreababii-bw.png',
 'BeyondMars-line.png',
 'ghoztcum-bw.png',
 'uhhhname-colour.png',
 '_jazmin-colour.png',
 'alikonagurl83-bw.png',
 'AdamBarnhouse-colour.png',
 'Quackattackaggie-colour.png',
 'Jasperthecat77-line.png',
 'The_Beaner-colour.png',
 'starienite-line.png',
 'jerrytt-line.png',
 'Salerno1717-colour.png',
 'Salerno1717-line.png',
 'Dreababii-line.png',
 'LongDistanceGuyy-bw.png',
 'seahorseVT-line.png',
 'OhLydia-line.png',
 'AdamBarnhouse-bw.png',
 'Dreababii-colour.png',
 'celest123-bw.png',
 'labatomi-colour.png',
 'starienite-bw.png',
 'OrangeCloud-colour.png',
 'ghoztcum-colour.png',
 'neszero-colour.png',
 'REALchampagnePAPI-line.png',
 'DemTurtlesCom-colour.png',
 'BonAnchovy-line.png',
 'bulgarianutter-line.png',
 'TD2705-line.png',
 'Jasperthecat77-colour.png',
 'Imbie81-line.png',
 'CapDance-line.png',
 'seahorseVT-colour.png',
 'JoisofLife-line.png',
 'plainclotheswoman-line.png',
 '_jazmin-line.png',
 'Mailing_a_Bear-line.png',
 'TD2705-bw.png',
 'arequest554-colour.png',
 'shripityshripit-colour.png',
 'bulgarianutter-bw.png',
 'celest123-colour.png',
 'AdamBarnhouse-line.png']

In [35]:
lisauth


Out[35]:
['elcielo17',
 'HoustonSoda2',
 'Cfar1994',
 'DoctorCrouchJrWho',
 'EPICsandwich225',
 'Tjalle60',
 'ChrisTaliaferro',
 'kayleemarie4386',
 'guurrllgetit',
 'greengal500',
 'anatomicallystuffed',
 'sundaylou',
 'rh0xx0rpwn3r98',
 'TTG_Zebra_Donkey',
 'RainyWeathers',
 'esmit438',
 'makebelievepoet',
 'Thepinkcursader',
 'pokewneedle',
 'dannydeforest',
 'ItWillBeMine',
 'Redchubs',
 'chet_lemon_party',
 'ilzdog',
 'Slay3rKenzie']

I want to save the list of usernames that submit images as png files in a dir. Currently when I call the list of authors it returns Redditor(user_name='theusername'). I want to return 'theusername'. Once this is resolved I can add '-line.png' '-bw.png' '-colour.png' to each folder.


In [36]:
lisr.author


Out[36]:
Redditor(user_name='Slay3rKenzie')

In [37]:
namlis = []

In [38]:
opsinz = open('/home/wcmckee/visignsys/index.meta', 'r')
panz = opsinz.read()

In [96]:
os.chdir(rmgzdays)

In [97]:
#panz()
for rdz in lisrgc:
    (rdz.title)
    #a(rdz.url)
    if 'http://i.imgur.com' in rdz.url:
        #print rdz.url
        print (rdz.url)
        url = rdz.url
        response = requests.get(url, stream=True)
        with open(str(rdz.author) + '-reference.png', 'wb') as out_file:
            shutil.copyfileobj(response.raw, out_file)
            del response


http://i.imgur.com/2RZps5l.jpg
http://i.imgur.com/Ja7q1B4.jpg
http://i.imgur.com/3IwbJqU.jpg
http://i.imgur.com/G29vFib.jpg
http://i.imgur.com/tJYg1i7.jpg
http://i.imgur.com/ysqmLby.jpg
http://i.imgur.com/Ri71eMt.jpg
http://i.imgur.com/ZZUzVJA.jpg
http://i.imgur.com/bj9FYZr.jpg

In [103]:
apsize = []

In [104]:
for rmglis in os.listdir(rmgzdays):
    print rmglis
    im = Image.open(rmglis)
    print im.size
    apsize.append(im.size)


RainyWeathers-reference.png
(400, 435)
makebelievepoet-reference.png
(2625, 1944)
elcielo17-reference.png
(4000, 3000)
pokewneedle-reference.png
(640, 1136)
ChrisTaliaferro-reference.png
(1456, 1456)
TTG_Zebra_Donkey-reference.png
(900, 1200)
Tjalle60-reference.png
(3264, 2448)
Cfar1994-reference.png
(1608, 1208)
HoustonSoda2-reference.png
(640, 640)

In [109]:
for numz in apsize:
    print numz[0]
    if numz[0] > 800:
        print ('greater than 800')
    else:
        print ('less than 800!')


400
less than 800!
2625
greater than 800
4000
greater than 800
640
less than 800!
1456
greater than 800
900
greater than 800
3264
greater than 800
1608
greater than 800
640
less than 800!

In [ ]:


In [98]:
doc = dominate.document(title='GetsDrawn')

with doc.head:
    link(rel='stylesheet', href='style.css')
    script(type='text/javascript', src='script.js')
    
    with div():
        attr(cls='header')
        h1('GetsDrawn')
        p(img('imgs/getsdrawn-bw.png', src='imgs/getsdrawn-bw.png'))
        h1('Updated ', strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
        p(panz)
        p(bodycom)
    
    

with doc:
    with div(id='body').add(ol()):
        for rdz in lisrgc:
            h1(rdz.title)
            #a(rdz.url)
            if 'http://i.imgur.com' in rdz.url:
                #print rdz.url
                p(img(rdz.url, src='%s' % rdz.url))
                
            #print rdz.url
            #if '.jpg' in rdz.url:
            #    img(rdz.urlz)
            #else:
            #    a(rdz.urlz)
            h1(str(rdz.author))
            
            #li(img(i.lower(), src='%s' % i))

    with div():
        attr(cls='body')
        p('GetsDrawn is open source')
        a('https://github.com/wcmckee/wcmckee')
        a('https://reddit.com/r/redditgetsdrawn')

#print doc

In [205]:
gtdrndic


Out[205]:
{'title': u'so if anyone has the time and would like a go at drawing me please feel free'}

In [264]:
docre = doc.render()

In [265]:
#s = docre.decode('ascii', 'ignore')

In [266]:
yourstring = docre.encode('ascii', 'ignore').decode('ascii')

In [267]:
indfil = ('/home/wcmckee/getsdrawndotcom/index.html')

In [268]:
mkind = open(indfil, 'w')
mkind.write(yourstring)
mkind.close()

In [269]:
#os.system('scp -r /home/wcmckee/getsdrawndotcom/ wcmckee@getsdrawn.com:/home/wcmckee/getsdrawndotcom')

In [ ]:
rsync -azP source destination

In [43]:
updatehtm = raw_input('Update index? Y/n')
updateref = raw_input('Update reference? Y/n')

if 'y' or '' in updatehtm:
    os.system('scp -r /home/wcmckee/getsdrawndotcom/index.html wcmckee@getsdrawn.com:/home/wcmckee/getsdrawndotcom/index.html')
elif 'n' in updatehtm:
    print 'not uploading'
if 'y' or '' in updateref:
    os.system('rsync -azP /home/wcmckee/getsdrawndotcom/ wcmckee@getsdrawn.com:/home/wcmckee/getsdrawndotcom/')


Update index? Y/nn
Update reference? Y/ny

In [ ]:
os.system('scp -r /home/wcmckee/getsdrawndotcom/index.html wcmckee@getsdrawn.com:/home/wcmckee/getsdrawndotcom/index.html')

In [208]:
os.system('scp -r /home/wcmckee/getsdrawndotcom/style.css wcmckee@getsdrawn.com:/home/wcmckee/getsdrawndotcom/style.css')


Out[208]:
256

In [208]:


In [ ]: