GotDrawn

Updating GetsDrawnDotCom with title feature.

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


In [159]:


In [217]:
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 [217]:


In [217]:


In [217]:


In [217]:


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

In [220]:
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 [221]:
fulcom = []
fuldic = dict()

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

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

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

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

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

In [226]:


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

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

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


its true

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

In [230]:


In [231]:
imgszpath


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

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

In [233]:
dayform


Out[233]:
'imgs/2015/02/22'

In [233]:


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


its true

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


its true

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


its false

In [237]:
datzpat


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

In [237]:


In [237]:


In [238]:
mntzpat


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

In [239]:
datzpat


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

In [239]:


In [239]:


In [239]:


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


its false

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

In [242]:
#if os.path(

In [243]:
print artes.date()


2015-02-22

In [244]:
print artes.time()


22:26:50.653109

In [245]:
dati = artes.datetime

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

In [247]:
import random

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

In [249]:
random.choice(imglis)


Out[249]:
'img2'

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


Out[250]:
[]

In [251]:
import PIL

In [252]:
imed = PIL

In [253]:
imed.PILLOW_VERSION


Out[253]:
'2.6.1'

In [254]:
#import pillow

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

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

In [267]:
imlocdir


Out[267]:
'/imgs/2015/02/22/akaatkins-reference.png'

In [257]:


In [268]:
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 [269]:
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 [270]:
fertz = datzpat + '/'

In [271]:
fertz


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

In [272]:
print doc


<!DOCTYPE html>
<html>
  <head>
    <title>GetsDrawn</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-22 22:26:50.653109+00:00</h1>
    </div>
  </head>
  <body>
    <div id="body">
      <ol>
        <p>
          <h1>Hello hello, I was hoping that y'all could illustrate my niece as a surprise gift to my sister!</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>buttercup93</p>
        <p>
          <h1>One of my closest friends turns 30 soon - would any of you kind artists care to draw her?</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>EasyTigrr</p>
        <p>
          <h1>Candid picture of my best friend and I in one of the most sincere expressions of happiness I have on camera. Would love to see it immortalized in drawing.</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>booketh</p>
        <p>
          <h1>Hello, would anybody mind drawing a picture of my friend and her boyfriend for her birthday? Thanks so much in advance!</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>cwakeford</p>
        <p>
          <h1>Could someone draw my 18 year old dog? Would love any style!</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>ahphenom</p>
        <p>
          <h1>Hey Reddit, I would appreciate it if you could draw my girlfriend</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>TheHappyCreeper</p>
        <p>
          <h1>Can someone draw me with my cat beard! =) lol</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>DauntlessStitch</p>
        <p>
          <h1>My girlfriend and I on a recent holiday</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>AnythingYouDontLike</p>
        <p>
          <h1>I love my silly kitten. Draw her?</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>iloveariiii</p>
        <p>
          <h1>My dad's first selfie.</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>slatsy</p>
        <p>
          <h1>My girlfriend would love it, if someone could draw her</h1>
        </p>
        <p>
          <img src="/imgs/2015/02/22/akaatkins-reference.png">
        </p>
        <p>NaviiAut</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 [273]:
os.chdir(fertz)

In [274]:
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


Hello hello, I was hoping that y'all could illustrate my niece as a surprise gift to my sister!
http://i.imgur.com/lMX41XE.jpg
buttercup93
One of my closest friends turns 30 soon - would any of you kind artists care to draw her?
http://i.imgur.com/fb1xXl0.png
EasyTigrr
Candid picture of my best friend and I in one of the most sincere expressions of happiness I have on camera. Would love to see it immortalized in drawing.
http://i.imgur.com/XoTKzBo.png
booketh
Hello, would anybody mind drawing a picture of my friend and her boyfriend for her birthday? Thanks so much in advance!
http://i.imgur.com/i4pOPYG.jpg
cwakeford
Could someone draw my 18 year old dog? Would love any style!
http://i.imgur.com/rXjGfzD.jpg
ahphenom
Hey Reddit, I would appreciate it if you could draw my girlfriend
http://i.imgur.com/LYBxrxf.jpg
TheHappyCreeper
Can someone draw me with my cat beard! =) lol
http://i.imgur.com/tnLZkda.jpg
DauntlessStitch
http://i.imgur.com/BUsh30I.png

Here's a quick sketch [Imgur](http://i.imgur.com/mB9NTeV.jpg)
My girlfriend and I on a recent holiday
http://i.imgur.com/qOFE41f.jpg
AnythingYouDontLike
I love my silly kitten. Draw her?
http://i.imgur.com/B5wbrvm.jpg
iloveariiii
 http://i.imgur.com/DtlYA9i.jpg 
My dad's first selfie.
http://i.imgur.com/SWlFnC9.jpg
slatsy
[Hope ya like it] (http://i.imgur.com/rDw2ei2.jpg)

This was a fun photo :D
I started trying to learn to draw a few days ago. Sorry for making your dad look like a north korean leader.

http://i.imgur.com/F7miAql.jpg




[deleted]
[deleted]
[Whatcha looking at?](http://ycsketch.blogspot.com/2015/02/rredditgetsdrawn-uslatsy-s-dad.html)
My girlfriend would love it, if someone could draw her
http://i.imgur.com/MaeUtRw.jpg
NaviiAut
I'm not sure if it ended up looking enough like her, but still [hope ya like it] (http://i.imgur.com/qnOlg4X.jpg)

In [58]:
flcz.author

flcz.body


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

In [ ]:


In [ ]:


In [ ]: