GotDrawn

Updating GetsDrawnDotCom with title feature.

Taking getsdrawndotcom code and adding in features such as comments. Getting rid of folder structure.


In [159]:


In [160]:
import os
import requests

import re
import json
import arrow

import praw

import dominate

from dominate.tags import * 

import shutil

from time import gmtime, strftime

In [160]:


In [161]:
gotdrndir = ('/home/wcmckee/gotdrawn/imgs')

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


Version 2.1.19 of praw is outdated. Version 2.1.20 was released Friday January 23, 2015.

In [163]:
fulcom = []
fuldic = dict()

In [164]:
getrn = r.get_subreddit('redditgetsdrawn')

In [165]:
rnew = getrn.get_new()

In [166]:
for rnc in rnew:
    fulcom.append(rnc)

In [167]:
artes = arrow.utcnow()

In [168]:
yrpath = artes.strftime('%Y')

In [168]:


In [169]:
mntpath = artes.strftime('%m')

In [170]:
dapth = artes.strftime('%d')

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


its true

In [180]:
imgszpath = (gotdrndir)
yrzpat = (imgszpath + '/' + yrpath)
mntzpat = (yrzpat + '/' + mntpath)
datzpat = (mntzpat + '/' + dapth)

In [180]:


In [181]:
imgszpath


Out[181]:
'/home/wcmckee/gotdrawn/imgs'

In [182]:
dayform = ('imgs/' + yrpath + '/' + mntpath + '/' + dapth)

In [183]:
dayform


Out[183]:
'imgs/2015/02/21'

In [183]:


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


its false

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


its false

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


its false

In [187]:
datzpat


Out[187]:
'/home/wcmckee/gotdrawn/imgs/2015/02/21'

In [187]:


In [187]:


In [188]:
mntzpat


Out[188]:
'/home/wcmckee/gotdrawn/imgs/2015/02'

In [189]:
datzpat


Out[189]:
'/home/wcmckee/gotdrawn/imgs/2015/02/21'

In [189]:


In [189]:


In [189]:


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


its true

In [191]:
#mthzpath = (yrzpat + '/' +

In [192]:
#if os.path(

In [192]:


In [193]:
print artes.date()


2015-02-21

In [194]:
print artes.time()


23:27:05.587817

In [195]:
dati = artes.datetime

In [196]:
#Random logo from logo folder.
#5 to choose from. import random, random choice out of a list

In [197]:
import random

In [198]:
imglis = ['img1', 'img2', 'img3', 'img4', 'img0']

In [199]:
random.choice(imglis)


Out[199]:
'img4'

In [200]:
os.listdir('/home/wcmckee/gotdrawn/logo')


Out[200]:
[]

In [201]:
import PIL

In [202]:
imed = PIL

In [203]:
imed.PILLOW_VERSION


Out[203]:
'2.6.1'

In [204]:
#import pillow

In [204]:


In [204]:


In [204]:


In [205]:
os.chdir('/home/wcmckee/gotdrawn/')

In [206]:
imlocdir = (dayform + '/' + str(flc.author) + '-reference.png')

In [207]:
imlocdir


Out[207]:
'imgs/2015/02/21/ShittyDuckFace-reference.png'

In [207]:


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

with doc.head:
    link(rel='stylesheet', href='style.css')
    script(type ='text/javascript', src='script.js')
    #str(str2)
    
    with div():
        attr(cls='header')
        h1('GetsDrawn')
        p(img('imgs/getsdrawn-bw.png', src='imgs/getsdrawn-bw.png'))
        #p(img('imgs/15/01/02/ReptileLover82-reference.png', src= 'imgs/15/01/02/ReptileLover82-reference.png'))
        h1('Updated ', str(artes.datetime))
        #p(panz)
        #p(bodycom)
    
    

with doc:
    with div(id='body').add(ol()):
        for flc in fulcom:
            if 'http://i.imgur.com' in flc.url:
                p(h1(flc.title))
                p(img(imlocdir, src= imlocdir))
                #p(img(flc.url, src = flc.url))
                p(str(flc.author))
                #res = requests.get(flc.url, stream=True)
                #with open(str(flc.author) + '-' + str(artes.date()) + '-reference.png', 'wb') as outfil:
                #    shutil.copyfileobj(res.raw, outfil)
                #    del res
                
                
            
        for flcz in flc.comments:
                p(flcz.body)
        
        
        #for rdz in reliz:
            #h1(rdz.title)
            #a(rdz.url)
            #p(img(rdz, src='%s' % rdz))
            #print rdz
            #p(img(rdz, src = rdz))
            #p(rdz)


                
            #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('GotDrawn is open source')
        a('https://github.com/getsdrawn/getsdrawndotcom')
        a('https://reddit.com/r/redditgetsdrawn')

#print doc

In [209]:
docre = doc.render()
#s = docre.decode('ascii', 'ignore')
yourstring = docre.encode('ascii', 'ignore').decode('ascii')
indfil = ('/home/wcmckee/gotdrawn/index.html')
mkind = open(indfil, 'w')
mkind.write(yourstring)
mkind.close()

In [ ]:


In [ ]:


In [210]:
fertz = datzpat + '/'

In [211]:
fertz


Out[211]:
'/home/wcmckee/gotdrawn/imgs/2015/02/21/'

In [109]:
print doc


<!DOCTYPE html>
<html>
  <head>
    <title>GotDrawn</title>
    <link href="style.css" rel="stylesheet"><script src="script.js" type="text/javascript"></script>
    <div class="header">
      <h1>GetsDrawn</h1>
      <p>
        <img src="imgs/getsdrawn-bw.png">
      </p>
      <h1>Updated 2015-02-21 21:26:42.626446+00:00</h1>
    </div>
  </head>
  <body>
    <div id="body">
      <ol>
        <p>
          <h1>Would you be willing to draw my cousin and her husband for his birthday? I know they'd love it! :)</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>ram1n</p>
        <p>
          <h1>My wife almost 19 years of marriage, can someone draw her?</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>tubarao2002</p>
        <p>
          <h1>Can anyone draw this photo of my grandma taken when she was dating my grandpa?</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>sailorchell</p>
        <p>
          <h1>Care to draw me viewing the White Cliffs of Dover?</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>sentimentation</p>
        <p>
          <h1>My sister, unaware she had sniffed the flowers so closely. I thought it might be fun to draw.</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>moulinroux</p>
        <p>
          <h1>I'd love to see you guys draw my son in some cool outfits! (any and all styles welcome!)</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>seriousherenow</p>
        <p>
          <h1>Can someone draw this older photo of my daughter?</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>zombreness</p>
        <p>
          <h1>Can anyone draw my neice? So cute we put her in the bin (not a real bin)</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>emotionalbeever</p>
        <p>
          <h1>Hey RGD! I would love to have my beautiful bestfriend drawn. It would make an amazing gift. Thanks. :)</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>Dispersonated</p>
        <p>
          <h1>It's lambing season! Here's me and yesterday's newborn!</h1>
        </p>
        <p>
          <img src="imgs/ShittyDuckFace-2015-02-21-reference.png">
        </p>
        <p>obsessedwithmydog</p>
      </ol>
    </div>
    <div class="body">
      <p>GotDrawn is open source</p>
      <a>https://github.com/getsdrawn/getsdrawndotcom</a>
      <a>https://reddit.com/r/redditgetsdrawn</a>
    </div>
  </body>
</html>

In [212]:
os.chdir(fertz)

In [ ]:
for flc in fulcom:
    if 'http://i.imgur.com' in flc.url:
        print flc.title
        print flc.url
        print flc.author
        res = requests.get(flc.url, stream=True)
        with open(str(flc.author) + '-' + str(artes.date()) + '-reference.png', 'wb') as outfil:
            shutil.copyfileobj(res.raw, outfil)
            del res
            
        for flcz in flc.comments:
            print flcz.body

In [58]:
flcz.author

flcz.body


Out[58]:
u'[Bahh :3](http://ycsketch.blogspot.com/2015/02/rredditgetsdrawn-uobsessedwithmydog.html)'

In [ ]:


In [ ]:


In [ ]: