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]:
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
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})
In [217]:
decict
Out[217]:
In [218]:
pandic
Out[218]:
In [219]:
comdict
Out[219]:
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})
In [223]:
decict
Out[223]:
In [224]:
fddict
Out[224]:
In [225]:
qwedict = decict.items() + fddict.items()
In [262]:
alldixz = dict()
In [269]:
for qwpz in qwedict:
print qwpz
alldixz.update({qwpz: 'test'})
In [270]:
alldixz
Out[270]:
In [271]:
qwedict
Out[271]:
In [227]:
for coaz in comply:
print coaz
for coa in coaz:
print coa.body
print coa.author
In [228]:
serz = Series(fddict)
In [229]:
fddict
Out[229]:
In [230]:
fddict.keys()
Out[230]:
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
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})
In [237]:
chedict
Out[237]:
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)
In [241]:
imcom
Out[241]:
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
In [245]:
for pain in docin.parent.children:
print pain
In [246]:
doc.body.parent.children
Out[246]:
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
In [257]:
rgdir = ('/home/wcmckee/rgdrecentReference/')
In [258]:
doc.render()
Out[258]:
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")
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]:
In [142]:
givmd()
Out[142]:
In [143]:
savedate
Out[143]:
In [144]:
deepone = str(savedate + '.md')
In [145]:
deepone
Out[145]:
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]:
In [154]:
savinx = open(str(deepone), 'w')
In [155]:
savinx.write(str(rgdef))
In [156]:
savinx.close()
In [157]:
deepone
Out[157]:
In [158]:
decict
Out[158]:
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]:
In [164]:
feram = pd.DataFrame(fepan)
In [165]:
fepan
Out[165]:
In [166]:
feram
Out[166]:
In [167]:
mepan
Out[167]:
In [168]:
defed = DataFrame(depan)
In [169]:
#defed.append(fepan)
In [170]:
depan
Out[170]:
In [171]:
fepan
Out[171]:
In [172]:
mergz = depan.append(fepan)
In [173]:
mergz
Out[173]:
In [173]:
In [174]:
defed
Out[174]:
In [175]:
defhtml = defed.to_html()
In [176]:
wrhtm = open('index.html', 'w')
wrhtm.write(defhtml)
wrhtm.close()
In [176]:
In [176]:
In [ ]: