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 [200]:
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 [201]:
chdira = ('/home/wcmckee/artcontroldrawsyou')
os.chdir(chdira)

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

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

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

In [205]:
decict = dict()

In [206]:
subz = getrddraw.get_new()

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

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

def apred(deciz):
    
    return (deciz)

In [209]:
apred('omg')


Out[209]:
'omg'

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

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

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


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

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

# <codecell>

rdnew = []

# <codecell>

rdnew

# <codecell>

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

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

In [216]:
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_2ofert
Could someone draw my girlfriend and me?
http://i.imgur.com/hUlG5Vc.jpg
Girgir55
None
0
[]
t3_2ofgfi
My favorite woman in the world is my mom. This is a picture of her as a young woman. Could you please draw her?
http://imgur.com/cOD4le7
Nattyzee3
None
0
[]
t3_2oewzr
Care to draw us weirdos?
http://i.imgur.com/QrMunEg.jpg
mischiefismychicken
None
0
[]
t3_2of3z3
Would anyone like to draw me?
http://imgur.com/kbAy4Vw
CD5700
None
2
[<praw.objects.Comment object at 0x14f7970>]
t3_2of5h8
I love this picture of my inlaws, could someone draw it?
http://imgur.com/NoSvCbt
Sectr9goddess
None
0
[]
t3_2of779
Me with some lovely flowers
http://imgur.com/zkAWMic
leannimals
None
3
[<praw.objects.Comment object at 0x14f7a70>, <praw.objects.Comment object at 0x14f7350>]
t3_2of9aw
Anyone want to draw me as a green witch? :)
http://i.imgur.com/eTVYxje.jpg
autumnwolfmoon89
None
0
[]
t3_2oexll
Would love someone to draw my dog.
http://i.imgur.com/occiAsF.jpg?1
asm1th
None
1
[<praw.objects.Comment object at 0x16f71f0>]
t3_2oeu9i
Me being a desert fox in the Mojave!
http://imgur.com/hWHlxKS
arianathefox
None
2
[<praw.objects.Comment object at 0x168bd10>]
t3_2oeu4a
I got a new haircut - would anyone like to draw me with it?
http://imgur.com/a/g8Nx6
MrsBoris
None
6
[<praw.objects.Comment object at 0x17304f0>, <praw.objects.Comment object at 0x1699630>]
t3_2oet0z
My nephews and I in Lake George. It would be so cool to see us drawn somewhere magical.
http://m.imgur.com/Is2M1EA
kachie1317
None
0
[]
t3_2oeqtn
I'd love to give my big sister a drawing of us for Christmas! Anyone out there who wants to give iT a try?
http://imgur.com/8NdHMRJ
SofieBuyse
None
0
[]
t3_2oepd8
Painting with my dog!
http://i.imgur.com/k40b2YB.jpg
Taroh
None
0
[]
t3_2oeo0c
My daughter and her sleeping cousin. Draw their first meeting?!
http://imgur.com/dMA1Ns3
babydaisy611
None
0
[]
t3_2oelz3
My Son's first ever baseball game with Daddy.
http://imgur.com/ndXEDmE
LiamsDaddy
None
0
[]
t3_2oeixy
Please, draw myself and my girlfriend. Selfie at the beach! Any styles welcome, thanks so much! ;)
http://imgur.com/9nplYrE
jpesmeraldo
None
0
[]
t3_2oei8o
My daughter from a fun little photo project we did together :)
http://imgur.com/7Q7rjdC
Lileaspirals
None
0
[]
t3_2oehed
Me and my beautiful wife on the happiest day of my life
http://imgur.com/3uQgoyL
TylerMills
None
0
[]
t3_2oegan
Anyone want draw my (hopefully) soon to be fiancee from her favorite picture?
http://imgur.com/a/fnKuP
sirwes
None
0
[]
t3_2oef1n
Please draw me and my soon to be SO as a surprise for him please?
http://imgur.com/a/x5gWO
fletchdoll
None
0
[]
t3_2oebgk
Would love a fun picture of my little boy please.
http://imgur.com/M2LjhZ8
oldwesty
None
0
[]
t3_2oe9hg
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!
http://imgur.com/a/KjDMi
blasejade
None
8
[<praw.objects.Comment object at 0x173e310>, <praw.objects.Comment object at 0x16f70d0>, <praw.objects.Comment object at 0x163bb70>]
t3_2oe8kl
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
http://imgur.com/cnE21iX
jazzillaa
None
2
[<praw.objects.Comment object at 0x17306f0>]
t3_2oe876
My little man a few months ago. Would love to see any of the talented artists recreate it.
http://i.imgur.com/aEDRodb.jpg
nickel45
None
0
[]
t3_2oe6ml
Good afternoon, Reddit artists! Here is me waiting at the doctor's office. All creative styles welcome! :)
http://i.imgur.com/eefMUpb.jpg
Sarahbelle89
None
3
[<praw.objects.Comment object at 0x1699cd0>, <praw.objects.Comment object at 0x173edf0>]

In [217]:
decict


Out[217]:
{'downs': 0,
 'example': 'wcmckee',
 'title': u"Good afternoon, Reddit artists! Here is me waiting at the doctor's office. All creative styles welcome! :)",
 'ups': 1,
 'url': u'http://i.imgur.com/eefMUpb.jpg'}

In [218]:
pandic


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

In [219]:
comdict


Out[219]:
{'comtxt': [<praw.objects.Comment at 0x1699cd0>,
  <praw.objects.Comment at 0x173edf0>]}

In [220]:
comply = []

In [221]:
fddict = dict()

In [222]:
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})


[Oil on canvas](http://i.imgur.com/ddwDjyc.jpg)
seanmillsartist
1417844682.0
[<praw.objects.Comment object at 0x16f7370>]
What a fun sense of scale! I hope you don't mind being a [flower](http://i.im...
koscheislittleducky
1417843559.0
[<praw.objects.Comment object at 0x16e1570>]
Awesome pic! When I get home I'll be sure to draw it later :)
angryfishtaco
1417844631.0
[]
Something different! http://imgur.com/AydhCrX
danceswithshamans
1417831727.0
[]
[Woodburning and gouache](http://i.imgur.com/CyQpYKO.jpg)
Katlix
1417834244.0
[<praw.objects.Comment object at 0x1699ab0>]
http://imgur.com/lukCRBH

TeachersPen
1417835288.0
[<praw.objects.Comment object at 0x17304b0>, <praw.objects.Comment object at 0x169f5d0>]
http://i.imgur.com/9SXs1JV.png?1

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

[Full Size](http://i.imgur...
seanmillsartist
1417826522.0
[<praw.objects.Comment object at 0x16f73d0>, <praw.objects.Comment object at 0x163b1d0>]
I think this one turned out pretty well. Here you go: http://imgur.com/DAFuZI...
clsanchez26
1417833988.0
[]
https://i.imgur.com/vZqYg20.jpg
bcsketches
1417843414.0
[]
[deleted]
None
1417826464.0
[<praw.objects.Comment object at 0x14f7570>]
[mostly ballpoint](http://ugocapetoart.blogspot.com/2014/12/mostly-ballpoint-...
ugocapeto
1417820228.0
[<praw.objects.Comment object at 0x16e1970>]
I just got sketchbook for my tablet. I've never used a digital program for dr...
danceswithshamans
1417824385.0
[]

In [223]:
decict


Out[223]:
{'author': Redditor(user_name='danceswithshamans'),
 'body': 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",
 'created': 1417824385.0,
 'downs': 0,
 'example': 'wcmckee',
 'replies': [],
 'title': u"Good afternoon, Reddit artists! Here is me waiting at the doctor's office. All creative styles welcome! :)",
 'ups': 1,
 'url': u'http://i.imgur.com/eefMUpb.jpg'}

In [224]:
fddict


Out[224]:
{'comauthor': Redditor(user_name='danceswithshamans'),
 'combody': 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",
 'comdown': 0,
 'comup': 2,
 'testblah': 'testblah'}

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

In [262]:
alldixz = dict()

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


('body', 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")
('author', Redditor(user_name='danceswithshamans'))
('title', u"Good afternoon, Reddit artists! Here is me waiting at the doctor's office. All creative styles welcome! :)")
('url', u'http://i.imgur.com/eefMUpb.jpg')
('downs', 0)
('created', 1417824385.0)
('ups', 1)
('replies', [])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-269-8348bf85f7e4> in <module>()
      1 for qwpz in qwedict:
      2     print qwpz
----> 3     alldixz.update({qwpz: 'test'})

TypeError: unhashable type: 'list'

In [270]:
alldixz


Out[270]:
{'test': ('comup', 2),
 ('author', Redditor(user_name='danceswithshamans')): 'test',
 ('body',
  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"): 'test',
 ('created', 1417824385.0): 'test',
 ('downs', 0): 'test',
 ('title',
  u"Good afternoon, Reddit artists! Here is me waiting at the doctor's office. All creative styles welcome! :)"): 'test',
 ('ups', 1): 'test',
 ('url', u'http://i.imgur.com/eefMUpb.jpg'): 'test'}

In [271]:
qwedict


Out[271]:
[('body',
  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"),
 ('author', Redditor(user_name='danceswithshamans')),
 ('title',
  u"Good afternoon, Reddit artists! Here is me waiting at the doctor's office. All creative styles welcome! :)"),
 ('url', u'http://i.imgur.com/eefMUpb.jpg'),
 ('downs', 0),
 ('created', 1417824385.0),
 ('ups', 1),
 ('replies', []),
 ('example', 'wcmckee'),
 ('testblah', 'testblah'),
 ('comauthor', Redditor(user_name='danceswithshamans')),
 ('comdown', 0),
 ('combody',
  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"),
 ('comup', 2)]

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


[<praw.objects.Comment object at 0x16f7370>]
*Holy shit.* I was not expecting someone to actually paint the picture on an actual canvas, and now I'm over the moon. I love the way it was done! THANK YOU so much!
CD5700
[<praw.objects.Comment object at 0x16e1570>]
Wow I don't mind at all! This great thank you !
leannimals
[]
[]
[<praw.objects.Comment object at 0x1699ab0>]
Wow that is awesome!!
Lileaspirals
[<praw.objects.Comment object at 0x17304b0>, <praw.objects.Comment object at 0x169f5d0>]
WOW.  The shadows are dramatic-love this.
Nattyzee3
amazing.
EmplOTM
[]
[<praw.objects.Comment object at 0x16f73d0>, <praw.objects.Comment object at 0x163b1d0>]
Okay, seriously, how do people come up with that amazing stuff in just a few hours? It takes me an hour just to draw a crappy cartoon stickman from a tutorial on a website for kids.
shindyy
That looks amazing! How long did it take you?
clsanchez26
[]
[]
[<praw.objects.Comment object at 0x14f7570>]
Images that are filtered or manipulated are removed. Like yours.
ItWillBeMine
[<praw.objects.Comment object at 0x16e1970>]
Beautiful!
Lileaspirals
[]

In [228]:
serz = Series(fddict)

In [229]:
fddict


Out[229]:
{'comauthor': Redditor(user_name='danceswithshamans'),
 'combody': 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",
 'comdown': 0,
 'comup': 2,
 'testblah': 'testblah'}

In [230]:
fddict.keys()


Out[230]:
['testblah', 'comauthor', 'comdown', 'combody', 'comup']

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