Reddit Gets Drawn Snatch Script

Creates the website redditgetsdrawnrecentreference. It contains the 25 most recent posts on r/redditgetsdrawn. title, image url, and username

TODO: Contains artwork replies to each thread

This is a Python script that takes data from reddit and posts it to another subreddit. It also creates a html file with the images embed into. The images are the most recent 25 on r/redditgetsdrawn.

The script returns the comments from the most recent 25 posts along with the comments of comments.

Pandas is used to append everything into a series and DataFrame. The pandas allows youto easily append these together.

get all artwork and append into reference image -> artwork.

Generate sites again.

RedditGetsDrawn Snatch

This is a Python script that takes data from reddit and posts it to another subreddit. It also creates a html file with the images embed into. The images are the most recent 25 on r/redditgetsdrawn.

TODO

submit art to users via website

fix image sizes (need to scale down to 550px)

Save to server rather than imgur

Archieve, snapshots of rgd

more artcontrol

itwillbemine comments to html - currently being saved in contact

work on css, div up page, title, side, body, fo

update twitter with ONE IMAGE and announce that the list has been updated.

write blog post and submits to artcontroldrawsyou/blog

gets sticked post on reddit

delete about/contact page and have on all same page. can still have link to blog. about contact etc... along the top. other sections

post images to blog for archieve - save body to wcmckee.com/blog - md format?

nikola install - build site.

cronjob to update site ever ?? hours? 4?

photos section: latest 25 photos submitted to redditgetsdrawn. art section: latest 25 art submitted to redditgetsdrawn.

cleanup code

import pandas into it and removed things i dont need like dominate


In [1]:
import os
import random
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 *

In [2]:
chdira = ('/home/wcmckee/artcontroldrawsyou')
os.chdir(chdira)

In [3]:
r = praw.Reddit(user_agent='rgdsnatch')

# <codecell>

#r.login('artcontrol', 'taylor123vag!')

# <codecell>

rd = r.get_subreddit('redditgetsdrawn')

# <codecell>

subz = rd.get_hot().next()
istit = (subz.title)
istxt = (subz.selftext_html)
istick = (subz.stickied)

rdnewz = rd.get_new()

rdnew = []


---------------------------------------------------------------------------
ConnectionError                           Traceback (most recent call last)
<ipython-input-3-bd8c7bbb7df4> in <module>()
     11 # <codecell>
     12 
---> 13 subz = rd.get_hot().next()
     14 istit = (subz.title)
     15 istxt = (subz.selftext_html)

/usr/local/lib/python2.7/dist-packages/praw/__init__.pyc in get_content(self, url, params, limit, place_holder, root_field, thing_field, after_field, _use_oauth, object_filter)
    478                 self._use_oauth = _use_oauth  # pylint: disable-msg=W0201
    479             try:
--> 480                 page_data = self.request_json(url, params=params)
    481                 if object_filter:
    482                     page_data = page_data[object_filter]

/usr/local/lib/python2.7/dist-packages/praw/decorators.pyc in wrapped(reddit_session, *args, **kwargs)
    159     @wraps(function)
    160     def wrapped(reddit_session, *args, **kwargs):
--> 161         return_value = function(reddit_session, *args, **kwargs)
    162         if isinstance(return_value, dict):
    163             if return_value.get('error') == 304:  # Not modified exception

/usr/local/lib/python2.7/dist-packages/praw/__init__.pyc in request_json(self, url, params, data, as_objects, retry_on_error)
    517             url += '.json'
    518         if retry_on_error is None:
--> 519             response = self._request(url, params, data)
    520         else:
    521             response = self._request(url, params, data,

/usr/local/lib/python2.7/dist-packages/praw/__init__.pyc in _request(self, url, params, data, files, auth, timeout, raw_response, retry_on_error)
    380         while True:
    381             try:
--> 382                 response = handle_redirect()
    383                 _raise_response_exceptions(response)
    384                 self.http.cookies.update(response.cookies)

/usr/local/lib/python2.7/dist-packages/praw/__init__.pyc in handle_redirect()
    353                 response = self.handler.request(request=request.prepare(),
    354                                                 proxies=self.http.proxies,
--> 355                                                 timeout=timeout, **kwargs)
    356                 url = _raise_redirect_exceptions(response)
    357             return response

/usr/local/lib/python2.7/dist-packages/praw/handlers.pyc in wrapped(cls, _cache_key, _cache_ignore, _cache_timeout, **kwargs)
    134             # assumption only one request to a domain can be made at a
    135             # time), there isn't a better way to handle this.
--> 136             result = function(cls, **kwargs)
    137             # The handlers don't call `raise_for_status` so we need to ignore
    138             # status codes that will result in an exception that should not be

/usr/local/lib/python2.7/dist-packages/praw/handlers.pyc in wrapped(cls, _rate_domain, _rate_delay, **kwargs)
     53                     time.sleep(delay)
     54                 lock_last[1] = now
---> 55                 return function(cls, **kwargs)
     56         return wrapped
     57 

/usr/local/lib/python2.7/dist-packages/praw/handlers.pyc in request(self, request, proxies, timeout, **_)
     89         """
     90         return self.http.send(request, proxies=proxies, timeout=timeout,
---> 91                               allow_redirects=False)
     92 RateLimitHandler.request = RateLimitHandler.rate_limit(
     93     RateLimitHandler.request)

/usr/local/lib/python2.7/dist-packages/requests/sessions.pyc in send(self, request, **kwargs)
    571 
    572         # Send the request
--> 573         r = adapter.send(request, **kwargs)
    574 
    575         # Total elapsed time of the request (approximately)

/usr/local/lib/python2.7/dist-packages/requests/adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
    413 
    414         except (ProtocolError, socket.error) as err:
--> 415             raise ConnectionError(err, request=request)
    416 
    417         except MaxRetryError as e:

ConnectionError: ('Connection aborted.', gaierror(-3, 'Temporary failure in name resolution'))

In [ ]:
reddraw = praw.Reddit(user_agent='rgdsnatch')

In [ ]:
getrddraw = reddraw.get_subreddit('redditgetsdrawn')

In [ ]:
decict = dict()

In [ ]:
subz = getrddraw.get_new()

In [ ]:
#class TestRedditFunction(unittest.TestCase):
    
#    def setUp(self):
#        self.seq = reddraw.get_subreddit('redditgetsdrawn')
        
#    def testredit(self):
#        drawnew('redditgetsdrawn')

In [ ]:
def drawnew(subred):
    getrdraw = reddraw.get_subreddit(subred)
    return getrdraw

def apred(deciz):
    
    return (deciz)

In [4]:
apred('omg')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-7e45b1d89c13> in <module>()
----> 1 apred('omg')

NameError: name 'apred' is not defined

In [5]:
rdrws = drawnew('redditgetsdrawn')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-d0e313c9aeb2> in <module>()
----> 1 rdrws = drawnew('redditgetsdrawn')

NameError: name 'drawnew' is not defined

In [6]:
rtohr = rdrws.get_controversial_from_all()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-3197d4b61113> in <module>()
----> 1 rtohr = rdrws.get_controversial_from_all()

NameError: name 'rdrws' is not defined

In [29]:
for imgz in rtohr:
    #print imgz.selftext
    print imgz.num_comments


6
33
26
8
71
53
7
23
61
6
20
59
58
10
5
14
3
21
7
26
56
37
4
15
2

In [30]:
rdnewz = getrddraw.get_new()

# <codecell>

rdnew = []

# <codecell>

rdnew

# <codecell>

for uz in rdnewz:
    #print uz
    rdnew.append(uz)

In [31]:
datelis = []
refdic = {}
rgdef = dict()
comdefz = []

In [32]:
for rdz in rdnew:
    print rdz.name
    print rdz.title
    print rdz.url
    print rdz.author
    print rdz.secure_media
    print rdz.num_comments
    print rdz.comments
    comdefz.append(rdz.comments)
    datelis.append(rdz.title)
    datelis.append(rdz.url)
    datelis.append(rdz.author)
    comdict = {'comtxt':rdz.comments}
    rgdef.update({rdz.author: rdz.url})
    pandic = DataFrame(rdz.json_dict)
    decict.update({'url':rdz.url})
    decict.update({'title':rdz.title})
    decict.update({'ups': rdz.ups})
    decict.update({'downs': rdz.downs})


t3_2pp1sn
Could anyone draw my girlfriend and I on our first anniversary? All styles welcome!
http://imgur.com/e3TO8WY
RunOttawa613
None
0
[]
t3_2ppl64
This was our first date as an actual couple. I would love to frame an awesome drawing of this picture!
http://imgur.com/Pxbfj7t
labatomi
None
0
[]
t3_2pptx4
Hello all, i was wondering if you could draw my grandparents! It is their 50th anniversary on 12/30 and i would love to have a drawing of this to bring them when i go out to visit next week.
http://imgur.com/K8FaNZe
youwinabagel
None
0
[]
t3_2pq5u8
My mom and even better grandmom with my daughter. All styles appreciated.
http://i.imgur.com/GwMlzuY.jpg
THORGNASH
None
0
[]
t3_2pq60d
Please feel free to draw me and my ridiculous bed head hair
http://i.imgur.com/ADUwATv.jpg
neszero
None
0
[]
t3_2ppesu
I would absolutely love it if someone could draw up these photos for me. My friend told me about "Redditgetsdrawn" the other day and I just had to get it checked out. This album is pictures of my family
http://imgur.com/a/ozPX2
Salerno1717
None
0
[]
t3_2pplo2
I'd really love it if someone could draw me and my boyfriend in a picture together :)
http://imgur.com/a/4krBq
LongDistanceGuyy
None
0
[]
t3_2pq98z
The first time my pup meets Santa! Would anyone like to draw my puppy and me?
https://i.imgur.com/mNLTYgb.jpg
seahorseVT
None
0
[]
t3_2pptlj
Can you guys draw my kid?
http://i.imgur.com/jyS6XBA.jpg
The_Beaner
None
0
[]
t3_2pps2w
Anyone interested in drawing my pet birds. This is Reina. The album also has pics of Princess
http://imgur.com/a/gehdT#1
JoisofLife
None
0
[]
t3_2pouou
RDG please draw our oldest son and our youngest son - any style welcome, go nuts!
http://imgur.com/dYJaJKc
MrsEvil
None
0
[]
t3_2povgd
Just me and my puppy. Maybe a cool last minute Christmas gift for my boyfriend :)
http://i.imgur.com/RItRgwA.jpg
koalapants
None
0
[]
t3_2pozvh
Would you please draw my brother and sis-in-law on their wedding day? They would love a this!
http://imgur.com/zSTlTX1
meetvirginia5
None
0
[]
t3_2poq79
Could you draw me, enjoying December on Whitsunday Island, Australia? I'd love a Christmas hat. Thanks.
http://imgur.com/hnKTHQq
Mrq001
None
0
[]
t3_2pp9gr
Anyone want to take a shot at drawing my girlfriend and I being silly?
http://imgur.com/qkLpt8H
reldritch
None
2
[<praw.objects.Comment object at 0x1ab4c70>, <praw.objects.Comment object at 0x197bd10>]
t3_2ppc0s
Would anyone be willing to take a stab at drawing my little guy with these pumpkins? We would just love it!
http://i.imgur.com/uYJlhhj.jpg
clareedward
None
0
[]
t3_2ppikn
My grandad cleaning the courtyard.
http://imgur.com/NQltHha
ssdesv
None
0
[]
t3_2pph1d
could some of you talented artists draw your version of me and my girlfriend?
http://imgur.com/aCU1Uha
hannahgendron
None
0
[]
t3_2ppaty
Would anyone be kind enough to draw my wife and daughter? Sorry for potato quality.
http://i.imgur.com/p5zvZkg.jpeg
dizzle67
None
0
[]
t3_2pp8b2
This is one of my happiest moments, and I would love to see it through your artist eyes! Thank you!!
http://imgur.com/B0J5Pox
Gabbylovesdogs
None
0
[]
t3_2ppc11
People always tell me i look like a viking, but a friendly viking. Please draw me as a friendly viking :)
http://imgur.com/MYY9B2c
rallemand3000
None
0
[]
t3_2ppcqw
My happy boy!
http://i.imgur.com/FJq12JX.jpg
SomeMomThings
None
0
[]
t3_2ppmqr
DRAW ME PLEASE!
http://imgur.com/W1ddJGH
stever712
None
0
[]
t3_2ppse6
My girlfriend and her dog Molly
http://imgur.com/ZCDDTz8
bogdy92
None
0
[]
t3_2ppuu6
This photo of my SO and I seems timeless - I'd love to see our moment through your eyes!
http://i.imgur.com/57pjRa3.png
khanbot
None
0
[]

In [36]:
decict


Out[36]:
{'downs': 0,
 'title': u"This photo of my SO and I seems timeless - I'd love to see our moment through your eyes!",
 'ups': 0,
 'url': u'http://i.imgur.com/57pjRa3.png'}

In [37]:
pandic


Out[37]:
Empty DataFrame
Columns: array([], dtype=object)
Index: array([], dtype=object)

In [38]:
comdict


Out[38]:
{'comtxt': []}

In [39]:
comply = []

In [40]:
fddict = dict()

In [41]:
fdz.body


Out[41]:
u"I drew a couple of pictures for users here back when this sub was starting out. I've been gone a while and damn has this place grown! I'm amazed at the level of talent here, and I'd be honored if anyone takes the time to draw us.\n\nAny and all styles appreciated. :)"

In [42]:
for comaq in comdefz:
    for fdz in comaq:
        print fdz
        print fdz.author
        print fdz.created_utc
        print fdz.replies
        fddict.update({'combody': fdz.body})
        fddict.update({'comauthor': fdz.author})
        fddict.update({'comup': fdz.ups})
        fddict.update({'comdown': fdz.downs})
        
        comply.append(fdz.replies)
        decict.update({'created':fdz.created_utc})
        decict.update({'author': fdz.author})
        decict.update({'body':fdz.body})
        decict.update({'replies':fdz.replies})


I drew a couple of pictures for users here back when this sub was starting ou...
reldritch
1418925056.0
[]
you were fun to draw reldritch, but i had a tough time with your lady. Had a ...
jaynewk
1418946590.0
[]

In [43]:
decict


Out[43]:
{'author': Redditor(user_name='jaynewk'),
 'body': u'you were fun to draw reldritch, but i had a tough time with your lady. Had a hard time with the kissy face... :) Oh well, it was a quick sketch. Might visit it with color, but here ya go.\n\nhttp://imgur.com/XHw5X6t',
 'created': 1418946590.0,
 'downs': 0,
 'replies': [],
 'title': u"This photo of my SO and I seems timeless - I'd love to see our moment through your eyes!",
 'ups': 0,
 'url': u'http://i.imgur.com/57pjRa3.png'}

In [28]:
fddict


Out[28]:
{'comauthor': Redditor(user_name='flylike'),
 'combody': u'[sketch](http://flylikesart.blogspot.no/2014/12/ulaceandvinegar.html)',
 'comdown': 0,
 'comup': 4}

In [29]:
qwedict = decict.items() + fddict.items()

In [30]:
alldixz = dict()

In [33]:
for qwpz in qwedict:
    print qwpz
    alldixz.update({qwpz: 'test'})


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-33-8348bf85f7e4> in <module>()
----> 1 for qwpz in qwedict:
      2     print qwpz
      3     alldixz.update({qwpz: 'test'})

NameError: name 'qwedict' is not defined

In [ ]:
alldixz

In [ ]:
qwedict

In [ ]:
for coaz in comply:
    print coaz
    for coa in coaz:
        print coa.body
        print coa.author

In [ ]:
serz = Series(fddict)

In [ ]:
fddict

In [ ]:
fddict.keys()

In [ ]:
def extractlinks(html):
    soup = BeautifulSoup(html)
    anchors = soup.findAll('a')
    links = []
    for a in anchors:
        links.append(a['href'])
    return links

In [232]:
cydict = fddict.values()

In [233]:
for itz in cydict:
    print itz


testblah
danceswithshamans
0
I just got sketchbook for my tablet. I've never used a digital program for drawing before or used anything but pencils. Came out dif than what I was going for but I'll learn! Lol http://imgur.com/cYEO26e
2

In [234]:
chedict = {'blah': 'testing'}

In [235]:
#fixurl = BeautifulSoup(fddict.values())

In [236]:
for coma in comdefz:
    #print coma
    #chedict.update({'first': coma})
    for co in coma:
        print co
        chedict.update({co.author: co.body})


[Oil on canvas](http://i.imgur.com/ddwDjyc.jpg)
What a fun sense of scale! I hope you don't mind being a [flower](http://i.im...
Awesome pic! When I get home I'll be sure to draw it later :)
Something different! http://imgur.com/AydhCrX
[Woodburning and gouache](http://i.imgur.com/CyQpYKO.jpg)
http://imgur.com/lukCRBH

http://i.imgur.com/9SXs1JV.png?1

I just traced it, I'm trying to learn how t...
[Oil on Canvas](http://i.imgur.com/aqhEneN.jpg?1)

[Full Size](http://i.imgur...
I think this one turned out pretty well. Here you go: http://imgur.com/DAFuZI...
https://i.imgur.com/vZqYg20.jpg
[deleted]
[mostly ballpoint](http://ugocapetoart.blogspot.com/2014/12/mostly-ballpoint-...
I just got sketchbook for my tablet. I've never used a digital program for dr...

In [46]:
getsdrdir = ('/home/wcmckee/getsdrawndotcom/')

In [48]:
os.listdir(getsdrdir)


Out[48]:
['index.html']

In [237]:
chedict


Out[237]:
{Redditor(user_name='clsanchez26'): u'I think this one turned out pretty well. Here you go: http://imgur.com/DAFuZIk :D',
 Redditor(user_name='seanmillsartist'): u'[Oil on Canvas](http://i.imgur.com/aqhEneN.jpg?1)\n\n[Full Size](http://i.imgur.com/bCb9YW9.jpg)',
 Redditor(user_name='TeachersPen'): u'http://imgur.com/lukCRBH\n',
 None: u'[deleted]',
 Redditor(user_name='angryfishtaco'): u"Awesome pic! When I get home I'll be sure to draw it later :)",
 Redditor(user_name='Katlix'): u'[Woodburning and gouache](http://i.imgur.com/CyQpYKO.jpg)',
 'blah': 'testing',
 Redditor(user_name='danceswithshamans'): u'Something different! http://imgur.com/AydhCrX',
 Redditor(user_name='seanmillsartist'): u'[Oil on canvas](http://i.imgur.com/ddwDjyc.jpg)',
 Redditor(user_name='piranhathon'): u"http://i.imgur.com/9SXs1JV.png?1\n\nI just traced it, I'm trying to learn how to use the path tool on photoshop",
 Redditor(user_name='ugocapeto'): u'[mostly ballpoint](http://ugocapetoart.blogspot.com/2014/12/mostly-ballpoint-sketch.html)',
 Redditor(user_name='danceswithshamans'): u"I just got sketchbook for my tablet. I've never used a digital program for drawing before or used anything but pencils. Came out dif than what I was going for but I'll learn! Lol http://imgur.com/cYEO26e",
 Redditor(user_name='koscheislittleducky'): u"What a fun sense of scale! I hope you don't mind being a [flower](http://i.imgur.com/N9zG55O.jpg) fairy.",
 Redditor(user_name='bcsketches'): u'https://i.imgur.com/vZqYg20.jpg'}

In [238]:
#jsdum = json.loads(chedict)

In [239]:
rcoms = chedict.keys()
rvals = chedict.values()
imcom = []

In [240]:
for rvs in rvals:
    print rvs
    if '.jpg' or '.png' in rvs:
        imcom.append(rvs)


http://imgur.com/lukCRBH

I think this one turned out pretty well. Here you go: http://imgur.com/DAFuZIk :D
[Oil on Canvas](http://i.imgur.com/aqhEneN.jpg?1)

[Full Size](http://i.imgur.com/bCb9YW9.jpg)
[deleted]
Awesome pic! When I get home I'll be sure to draw it later :)
[Woodburning and gouache](http://i.imgur.com/CyQpYKO.jpg)
testing
Something different! http://imgur.com/AydhCrX
[Oil on canvas](http://i.imgur.com/ddwDjyc.jpg)
http://i.imgur.com/9SXs1JV.png?1

I just traced it, I'm trying to learn how to use the path tool on photoshop
[mostly ballpoint](http://ugocapetoart.blogspot.com/2014/12/mostly-ballpoint-sketch.html)
I just got sketchbook for my tablet. I've never used a digital program for drawing before or used anything but pencils. Came out dif than what I was going for but I'll learn! Lol http://imgur.com/cYEO26e
What a fun sense of scale! I hope you don't mind being a [flower](http://i.imgur.com/N9zG55O.jpg) fairy.
https://i.imgur.com/vZqYg20.jpg

In [241]:
imcom


Out[241]:
[u'http://imgur.com/lukCRBH\n',
 u'I think this one turned out pretty well. Here you go: http://imgur.com/DAFuZIk :D',
 u'[Oil on Canvas](http://i.imgur.com/aqhEneN.jpg?1)\n\n[Full Size](http://i.imgur.com/bCb9YW9.jpg)',
 u'[deleted]',
 u"Awesome pic! When I get home I'll be sure to draw it later :)",
 u'[Woodburning and gouache](http://i.imgur.com/CyQpYKO.jpg)',
 'testing',
 u'Something different! http://imgur.com/AydhCrX',
 u'[Oil on canvas](http://i.imgur.com/ddwDjyc.jpg)',
 u"http://i.imgur.com/9SXs1JV.png?1\n\nI just traced it, I'm trying to learn how to use the path tool on photoshop",
 u'[mostly ballpoint](http://ugocapetoart.blogspot.com/2014/12/mostly-ballpoint-sketch.html)',
 u"I just got sketchbook for my tablet. I've never used a digital program for drawing before or used anything but pencils. Came out dif than what I was going for but I'll learn! Lol http://imgur.com/cYEO26e",
 u"What a fun sense of scale! I hope you don't mind being a [flower](http://i.imgur.com/N9zG55O.jpg) fairy.",
 u'https://i.imgur.com/vZqYg20.jpg']

In [242]:
#fuldoc = doc.render()

In [242]:


In [243]:
doc = dominate.document(title='Dominate your HTML')

with doc.head:
    link(rel='stylesheet', href='style.css')
    script(type='text/javascript', src='script.js')

with doc:
    with div(id='header').add(ol()):
        for imz in imcom:
            #print imz
            p(imz)

    #with div():
     #   attr(cls='body')
     #   p('Lorem ipsum..')

#print doc

In [244]:
for docin in doc.head.children:
    print docin


<title>Dominate your HTML</title>
<link href="style.css" rel="stylesheet">
<script src="script.js" type="text/javascript"></script>

In [245]:
for pain in docin.parent.children:
    print pain


<title>Dominate your HTML</title>
<link href="style.css" rel="stylesheet">
<script src="script.js" type="text/javascript"></script>

In [246]:
doc.body.parent.children


Out[246]:
[<dominate.tags.head at 14f44d0: 0 attributes, 3 children>,
 <dominate.tags.body at 14f4430: 0 attributes, 1 child>]

In [246]:


In [247]:
#soup = BeautifulSoup(doc)

#print(soup.prettify())

In [248]:
#extractlinks()

In [249]:
#for imc in imcom:
#    print imc

In [250]:
#doc.body

In [250]:


In [251]:
#doc.render()

In [252]:
#for dicaz in doc.children:
#    print dicaz

In [252]:


In [253]:
#for imz in imcom:
    
#    print imz

In [254]:
#for rez in rcoms:
#    print rez

In [254]:


In [255]:
#for rgt in rgdef.values():
#    if '.jpg' in rgt:
#        print rgt

In [256]:
import dominate
from dominate.tags import *

doc = dominate.document(title='RedditGetsDrawn Recent Reference')

with doc.head:
    link(rel='stylesheet', href='style.css')
    script(type='text/javascript', src='script.js')
    
    with div():
        attr(cls='header')
        h1('RedditGetsDrawn Recent Reference')
        p('updated ', strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))

    
    

with doc:
    with div(id='body').add(ol()):
        for rdz in rdnew:
            h1(rdz.title)
            a(rdz.url)
            if '.jpg' or '.png' 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)
            p(str(rdz.author))
            
            #li(img(i.lower(), src='%s' % i))

    with div():
        attr(cls='body')
        p('RGDRecentReference is open source')
        a('http://github.com/wcmckee/wcmckee')

#print doc


http://i.imgur.com/hUlG5Vc.jpg
http://imgur.com/cOD4le7
http://i.imgur.com/QrMunEg.jpg
http://imgur.com/kbAy4Vw
http://imgur.com/NoSvCbt
http://imgur.com/zkAWMic
http://i.imgur.com/eTVYxje.jpg
http://i.imgur.com/occiAsF.jpg?1
http://imgur.com/hWHlxKS
http://imgur.com/a/g8Nx6
http://m.imgur.com/Is2M1EA
http://imgur.com/8NdHMRJ
http://i.imgur.com/k40b2YB.jpg
http://imgur.com/dMA1Ns3
http://imgur.com/ndXEDmE
http://imgur.com/9nplYrE
http://imgur.com/7Q7rjdC
http://imgur.com/3uQgoyL
http://imgur.com/a/fnKuP
http://imgur.com/a/x5gWO
http://imgur.com/M2LjhZ8
http://imgur.com/a/KjDMi
http://imgur.com/cnE21iX
http://i.imgur.com/aEDRodb.jpg
http://i.imgur.com/eefMUpb.jpg

In [257]:
rgdir = ('/home/wcmckee/rgdrecentReference/')

In [258]:
doc.render()


Out[258]:
u'<!DOCTYPE html>\n<html>\n  <head>\n    <title>RedditGetsDrawn Recent Reference</title>\n    <link href="style.css" rel="stylesheet"><script src="script.js" type="text/javascript"></script>\n    <div class="header">\n      <h1>RedditGetsDrawn Recent Reference</h1>\n      <p>updated Sat, 06 Dec 2014 05:56:01 +0000</p>\n    </div>\n  </head>\n  <body>\n    <div id="body">\n      <ol>\n        <h1>Could someone draw my girlfriend and me?</h1>\n        <a>http://i.imgur.com/hUlG5Vc.jpg</a>\n        <p>\n          <img src="http://i.imgur.com/hUlG5Vc.jpg">\n        </p>\n        <p>Girgir55</p>\n        <h1>My favorite woman in the world is my mom. This is a picture of her as a young woman. Could you please draw her?</h1>\n        <a>http://imgur.com/cOD4le7</a>\n        <p>\n          <img src="http://imgur.com/cOD4le7">\n        </p>\n        <p>Nattyzee3</p>\n        <h1>Care to draw us weirdos?</h1>\n        <a>http://i.imgur.com/QrMunEg.jpg</a>\n        <p>\n          <img src="http://i.imgur.com/QrMunEg.jpg">\n        </p>\n        <p>mischiefismychicken</p>\n        <h1>Would anyone like to draw me?</h1>\n        <a>http://imgur.com/kbAy4Vw</a>\n        <p>\n          <img src="http://imgur.com/kbAy4Vw">\n        </p>\n        <p>CD5700</p>\n        <h1>I love this picture of my inlaws, could someone draw it?</h1>\n        <a>http://imgur.com/NoSvCbt</a>\n        <p>\n          <img src="http://imgur.com/NoSvCbt">\n        </p>\n        <p>Sectr9goddess</p>\n        <h1>Me with some lovely flowers</h1>\n        <a>http://imgur.com/zkAWMic</a>\n        <p>\n          <img src="http://imgur.com/zkAWMic">\n        </p>\n        <p>leannimals</p>\n        <h1>Anyone want to draw me as a green witch? :)</h1>\n        <a>http://i.imgur.com/eTVYxje.jpg</a>\n        <p>\n          <img src="http://i.imgur.com/eTVYxje.jpg">\n        </p>\n        <p>autumnwolfmoon89</p>\n        <h1>Would love someone to draw my dog.</h1>\n        <a>http://i.imgur.com/occiAsF.jpg?1</a>\n        <p>\n          <img src="http://i.imgur.com/occiAsF.jpg?1">\n        </p>\n        <p>asm1th</p>\n        <h1>Me being a desert fox in the Mojave!</h1>\n        <a>http://imgur.com/hWHlxKS</a>\n        <p>\n          <img src="http://imgur.com/hWHlxKS">\n        </p>\n        <p>arianathefox</p>\n        <h1>I got a new haircut - would anyone like to draw me with it?</h1>\n        <a>http://imgur.com/a/g8Nx6</a>\n        <p>\n          <img src="http://imgur.com/a/g8Nx6">\n        </p>\n        <p>MrsBoris</p>\n        <h1>My nephews and I in Lake George. It would be so cool to see us drawn somewhere magical.</h1>\n        <a>http://m.imgur.com/Is2M1EA</a>\n        <p>\n          <img src="http://m.imgur.com/Is2M1EA">\n        </p>\n        <p>kachie1317</p>\n        <h1>I\'d love to give my big sister a drawing of us for Christmas! Anyone out there who wants to give iT a try?</h1>\n        <a>http://imgur.com/8NdHMRJ</a>\n        <p>\n          <img src="http://imgur.com/8NdHMRJ">\n        </p>\n        <p>SofieBuyse</p>\n        <h1>Painting with my dog!</h1>\n        <a>http://i.imgur.com/k40b2YB.jpg</a>\n        <p>\n          <img src="http://i.imgur.com/k40b2YB.jpg">\n        </p>\n        <p>Taroh</p>\n        <h1>My daughter and her sleeping cousin. Draw their first meeting?!</h1>\n        <a>http://imgur.com/dMA1Ns3</a>\n        <p>\n          <img src="http://imgur.com/dMA1Ns3">\n        </p>\n        <p>babydaisy611</p>\n        <h1>My Son\'s first ever baseball game with Daddy.</h1>\n        <a>http://imgur.com/ndXEDmE</a>\n        <p>\n          <img src="http://imgur.com/ndXEDmE">\n        </p>\n        <p>LiamsDaddy</p>\n        <h1>Please, draw myself and my girlfriend. Selfie at the beach! Any styles welcome, thanks so much! ;)</h1>\n        <a>http://imgur.com/9nplYrE</a>\n        <p>\n          <img src="http://imgur.com/9nplYrE">\n        </p>\n        <p>jpesmeraldo</p>\n        <h1>My daughter from a fun little photo project we did together :)</h1>\n        <a>http://imgur.com/7Q7rjdC</a>\n        <p>\n          <img src="http://imgur.com/7Q7rjdC">\n        </p>\n        <p>Lileaspirals</p>\n        <h1>Me and my beautiful wife on the happiest day of my life</h1>\n        <a>http://imgur.com/3uQgoyL</a>\n        <p>\n          <img src="http://imgur.com/3uQgoyL">\n        </p>\n        <p>TylerMills</p>\n        <h1>Anyone want draw my (hopefully) soon to be fiancee from her favorite picture?</h1>\n        <a>http://imgur.com/a/fnKuP</a>\n        <p>\n          <img src="http://imgur.com/a/fnKuP">\n        </p>\n        <p>sirwes</p>\n        <h1>Please draw me and my soon to be SO as a surprise for him please?</h1>\n        <a>http://imgur.com/a/x5gWO</a>\n        <p>\n          <img src="http://imgur.com/a/x5gWO">\n        </p>\n        <p>fletchdoll</p>\n        <h1>Would love a fun picture of my little boy please.</h1>\n        <a>http://imgur.com/M2LjhZ8</a>\n        <p>\n          <img src="http://imgur.com/M2LjhZ8">\n        </p>\n        <p>oldwesty</p>\n        <h1>I was wondering if anyone could draw me? I just linked to the album that I save all my pictures in so you have multiple photo choices. Thanks!</h1>\n        <a>http://imgur.com/a/KjDMi</a>\n        <p>\n          <img src="http://imgur.com/a/KjDMi">\n        </p>\n        <p>blasejade</p>\n        <h1>Running out of gift ideas for my boyfriend for Christmas. I\'d love to give him a framed drawing of us on halloween for his desk</h1>\n        <a>http://imgur.com/cnE21iX</a>\n        <p>\n          <img src="http://imgur.com/cnE21iX">\n        </p>\n        <p>jazzillaa</p>\n        <h1>My little man a few months ago. Would love to see any of the talented artists recreate it.</h1>\n        <a>http://i.imgur.com/aEDRodb.jpg</a>\n        <p>\n          <img src="http://i.imgur.com/aEDRodb.jpg">\n        </p>\n        <p>nickel45</p>\n        <h1>Good afternoon, Reddit artists! Here is me waiting at the doctor\'s office. All creative styles welcome! :)</h1>\n        <a>http://i.imgur.com/eefMUpb.jpg</a>\n        <p>\n          <img src="http://i.imgur.com/eefMUpb.jpg">\n        </p>\n        <p>Sarahbelle89</p>\n      </ol>\n    </div>\n    <div class="body">\n      <p>RGDRecentReference is open source</p>\n      <a>http://github.com/wcmckee/wcmckee</a>\n    </div>\n  </body>\n</html>'

In [259]:
os.chdir(rgdir)

In [136]:
mkindex = open('index.html', 'w')
mkindex.write(str(doc))
mkindex.close()

In [137]:
#print str(doc)

In [138]:
print strftime("%a, %d %b %Y %H:%M:%S +0000")


Sat, 06 Dec 2014 11:35:26 +0000

In [139]:
savedate = strftime("%d" + "-" + "%m" + "-" + "%Y" + "-" + "%H")

In [140]:
def timeret():
    return strftime("%d" + "-" + "%m" + "-" + "%Y" + "-" + "%H")

def givmd():
    return str(savedate + '.md')

def givdic():
    return rgdir.replace('/', '-')

In [141]:
givdic()


Out[141]:
'-home-wcmckee-rgdrecentReference-'
timeret()

In [142]:
givmd()


Out[142]:
'06-12-2014-11.md'

In [143]:
savedate


Out[143]:
'06-12-2014-11'

In [144]:
deepone = str(savedate + '.md')

In [145]:
deepone


Out[145]:
'06-12-2014-11.md'

In [146]:
#os.chdir('/home/wcmckee/brobeur-blog-post/')

In [147]:
#brobeind = open('índex.html', 'r')

In [148]:
#brotest = open('índex.html', 'r')
#brotest.read()

In [149]:
redposts = ('/home/wcmckee/rgdrecentReference/posts/pandas')

In [152]:
os.chdir(redposts)

In [153]:
time.asctime()


Out[153]:
'Sat Dec  6 11:37:51 2014'

In [154]:
savinx = open(str(deepone), 'w')

In [155]:
savinx.write(str(rgdef))

In [156]:
savinx.close()

In [157]:
deepone


Out[157]:
'06-12-2014-11.md'

In [158]:
decict


Out[158]:
{'downs': 0,
 'example': 'wcmckee',
 'title': u'My little sister (glasses) and her wife on their wedding day. Same-sex marriage was finally legalized in our home state!',
 'ups': 1,
 'url': u'http://imgur.com/khvU7zu'}

In [159]:
decict.update({'datehour': givmd()})

In [160]:
depan = Series(decict)

In [161]:
fepan = Series(fddict)

In [162]:
mepan = (fepan)+(depan)

In [163]:
depan


Out[163]:
datehour                                                                                                            06-12-2014-11.md
downs                                                                                                                              0
example                                                                                                                      wcmckee
title       My little sister (glasses) and her wife on their wedding day. Same-sex marriage was finally legalized in our home state!
ups                                                                                                                                1
url                                                                                                         http://imgur.com/khvU7zu

In [164]:
feram = pd.DataFrame(fepan)

In [165]:
fepan


Out[165]:
testblah    testblah

In [166]:
feram


Out[166]:
                 0
testblah  testblah

In [167]:
mepan


Out[167]:
datehour    None
downs       None
example     None
testblah    None
title       None
ups         None
url         None

In [168]:
defed = DataFrame(depan)

In [169]:
#defed.append(fepan)

In [170]:
depan


Out[170]:
datehour                                                                                                            06-12-2014-11.md
downs                                                                                                                              0
example                                                                                                                      wcmckee
title       My little sister (glasses) and her wife on their wedding day. Same-sex marriage was finally legalized in our home state!
ups                                                                                                                                1
url                                                                                                         http://imgur.com/khvU7zu

In [171]:
fepan


Out[171]:
testblah    testblah

In [172]:
mergz = depan.append(fepan)

In [173]:
mergz


Out[173]:
datehour                                                                                                            06-12-2014-11.md
downs                                                                                                                              0
example                                                                                                                      wcmckee
title       My little sister (glasses) and her wife on their wedding day. Same-sex marriage was finally legalized in our home state!
ups                                                                                                                                1
url                                                                                                         http://imgur.com/khvU7zu
testblah                                                                                                                    testblah

In [173]:


In [174]:
defed


Out[174]:
<class 'pandas.core.frame.DataFrame'>
Index: 6 entries, datehour to url
Data columns:
0    6  non-null values
dtypes: object(1)

In [175]:
defhtml = defed.to_html()

In [176]:
wrhtm = open('index.html', 'w')
wrhtm.write(defhtml)
wrhtm.close()

In [176]:


In [176]:


In [ ]: