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

The script now filters the jpeg and png image and skips links to imgur pages. This needs to be fixed by getting the images from the imgur pages. It renames the image files to the redditor username followed by a -reference tag (and ending with png of course). It opens these files up with PIL and checks the sizes. It needs to resize the images that are larger than 800px to 800px. These images need to be linked in the index.html instead of the imgur altenatives.


In [1]:
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 [2]:
gtsdrndir = ('/home/wcmckee/getsdrawndotcom')

In [3]:
os.chdir(gtsdrndir)

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

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

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

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

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

In [8]:
#shtweet = []

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

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

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

In [12]:
#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 [13]:
#bodycom

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

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

In [16]:
lisrgc = []
lisauth = []

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

In [18]:
gtdrndic = dict()

In [19]:
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 [23]:
imgzdir = ('/home/wcmckee/getsdrawndotcom/imgs/')
yrzpat = (imgzdir + yearz)
monzpath = (yrzpat + '/' + monthz)
dayzpath = (monzpath + '/' + dayz)
rmgzdays = (dayzpath + '/reference')
imgzdays = (dayzpath + '/art')

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

In [25]:
ospacheck()


its true

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

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

#os.mkdir(monzpath)


its true

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

#os.mkdir(dayzpath)


its false

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


its false

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


its false

In [31]:
#artlist

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

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

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

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

In [36]:
os.chdir(imgzdays)

In [37]:
imgzdays


Out[37]:
'/home/wcmckee/getsdrawndotcom/imgs/15/01/17/art'

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

In [39]:
#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 [40]:
os.listdir('/home/wcmckee/getsdrawndotcom/imgs')


Out[40]:
['getsdrawn-bw.png', '15', '14']

In [41]:
lisauth


Out[41]:
['Konnii',
 'cabarl25',
 'Marsinator',
 'StacheKetchum',
 'warriorprincessdi',
 'DreiaTheNeedleArtist',
 'M3thKitty',
 'dadaduck',
 'alexandrass',
 'Tjkerk',
 'amsoell',
 'jarreddit',
 'JoeBFront',
 'unpleasantly',
 'JBadgerSKI',
 'MerpyP',
 'alvapossie',
 'AnnieOrangetree',
 'bossman74',
 'famousfamily7448',
 'mblack3',
 'BroShow',
 'jellybeannose',
 'wetmoose',
 'a_codfish']

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 [42]:
lisr.author


Out[42]:
Redditor(user_name='a_codfish')

In [43]:
namlis = []

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

In [45]:
os.chdir(rmgzdays)

In [46]:
#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/00xfqqm.jpg
http://i.imgur.com/nLTfGH6.jpg
http://i.imgur.com/NztzycZ.jpg
http://i.imgur.com/MqTSAyE.jpg
http://i.imgur.com/CgPrwE8.jpg
http://i.imgur.com/aReLZQ8.jpg
http://i.imgur.com/vxOfRK7.jpg
http://i.imgur.com/HHsuK3P.jpg
http://i.imgur.com/heE08Cv.jpg
http://i.imgur.com/OuyN0bJ.jpg
http://i.imgur.com/3g2iJxV.jpg
http://i.imgur.com/2j9Jjbo.jpg

In [47]:
apsize = []

In [48]:
basewidth = 600

In [57]:
for rmglis in os.listdir(rmgzdays):
    print rmglis
    #print rmglis.size
    #apsize.append(im.size)


IAmDaleGribble-reference.png
mpbosco11-reference.png
skylarwolfe97-reference.png
bikepsycho-reference.png
rickLteresa-reference.png
justchuck1070-reference.png
mrjb3-reference.png
jcastelletti-reference.png
yumyumyoshi-reference.png
BroShow-reference.png
kerlypso-reference.png
PerkyMaggot-reference.png
Sloths_and_palmtrees-reference.png
bgiu-reference.png
paulccole-reference.png

In [58]:
#basewidth = 300
#img = Image.open('somepic.jpg')
#wpercent = (basewidth/float(img.size[0]))
#hsize = int((float(img.size[1])*float(wpercent)))
#img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS)
#img.save('sompic.jpg')

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

In [60]:


In [61]:
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 [62]:
gtdrndic


Out[62]:
{'title': u'Can someone please draw me?All styles are welcome!'}

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

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

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

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

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

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

In [69]:
#rsync -azP source destination

In [70]:
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/ny
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 [ ]: