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, footer
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.
In [899]:
import os
import random
import requests
from bs4 import BeautifulSoup
import re
import json
import time
import praw
import dominate
from dominate.tags import *
In [900]:
os.chdir('/var/www/artcontroldrawsyou')
In [901]:
r = praw.Reddit(user_agent='rgdsnatch')
In [902]:
#r.login('artcontrol', 'taylor123vag!')
In [903]:
rd = r.get_subreddit('redditgetsdrawn')
In [904]:
subz = rd.get_hot().next()
istit = (subz.title)
istxt = (subz.selftext_html)
istick = (subz.stickied)
In [905]:
istit
Out[905]:
In [906]:
istxt
Out[906]:
In [907]:
if istick = True:
In [908]:
rdnewz = rd.get_new()
In [909]:
rdnew = []
In [910]:
rdnew
Out[910]:
In [911]:
for uz in rdnewz:
#print uz
rdnew.append(uz)
In [912]:
urzlis = []
titlis = []
In [913]:
#os.chdir('imgs')
In [914]:
for rdn in rdnew:
print rdn.url
urzlis.append(rdn.url)
titlis.append(rdn.author.name)
In [915]:
titlis
Out[915]:
In [916]:
jplis = []
In [917]:
from time import gmtime, strftime
In [918]:
for iz in jplis:
print iz
In [919]:
for urz in urzlis:
if '.jpg' in urz:
jplis.append(urz)
In [920]:
doc = dominate.document(title='artcontroldrawsyou')
In [920]:
In [921]:
with doc.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with doc:
with div():
attr(cls='header')
#<img src="smiley.gif" alt="Smiley face" height="42" width="42">
h1('artcontroldrawsyou!')
img(scr='logo.gif')
h2('go away artcontrol')
p(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
a('about', href='http://brobeur.com/artcontroldrawsyou/about')
a('contact', href='http://brobeur.com/artcontroldrawsyou/contact')
a('blog', href='http://brobeur.com/wcmckee.com/wcmckee/output')
with div(id='authors'):
for tits in titlis:
(tits)
(a(tits, href='https://reddit.com/u/%s' % tits))
with div(id='body').add(p()):
for i in jplis:
(img(i.lower(), src='%s' % i))
(a(i.lower(), href='%s' % i))
with div(id='footer'):
p(a('artcontroldrawsyou is open source', href='https://github.com/wcmckee/wcmckee-notebook'))
print doc
In [922]:
ophtml = open('index.html', 'w')
In [923]:
ophtml.write(str(doc))
In [924]:
ophtml.close()
In [925]:
'''def fcopy(src,dest):
"""
Copy file from source to dest. dest can include an absolute or relative path
If the path doesn't exist, it gets created
"""
dest_dir = os.path.dirname(dest)
try:
os.makedirs(dest_dir)
except os.error as e:
pass #Assume it exists. This could fail if you don't have permissions, etc...
shutil.copy(src,dest)'''
Out[925]:
cycle though folder and create file in each folder
In [926]:
#fcopy('/var/www/artcontroldrawsyou/home/')
In [927]:
for usz in titlis:
print usz
#os.mkdir(usz)
#os.chdir('/var/www/artcontroldrawsyou/home/' + usz)
In [928]:
'''for filz in titlis:
print filz
#os.chdir('/var/www/artcontroldrawsyou/home' + usz)
bulkc = dominate.document(title=filz)
with bulkc.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with bulkc:
with div():
attr(cls='header')
#<img src="smiley.gif" alt="Smiley face" height="42" width="42">
h1(filz)
img(scr='http://artcontrol.me/wp-content/uploads/2014/08/daenuhlyn-headcoloe.png')
h2('go away artcontrol')
with div(id='photographs'):
for tits in titlis:
h3(tits)
(a(tits, href='%s' % tits.lower))
with div(id='body').add(p()):
for i in jplis:
li(img(i.lower(), src='%s' % i))
li(a(i.lower(), href='%s' % i))
with div(id='footer'):
p(a('artcontroldrawsyou is opensource', href='https://github.com/wcmckee/wcmckee-notebook'))
with open('/var/www/artcontroldrawsyou/home/' + filz + '/index.html', 'w') as fout:
fout.write(str(bulkc))
#with open('index.html', 'w') as indx:
#bulkc = indx.write()
#print bulkc'''
Out[928]:
In [929]:
ransubz = random.randint(0,24)
In [930]:
print ransubz
In [931]:
ransev = rdnew[ransubz]
In [932]:
rgdautoz = str(ransev.author)
In [933]:
rgdsubred = str(ransev.subreddit)
In [934]:
sutit = ('[' + rgdsubred + ']')
In [935]:
sutit
Out[935]:
In [936]:
rgdaqwew = ('xpost[RGD]' + rgdautoz)
In [937]:
rgdaturo = str(ransev.url)
In [938]:
rgdatit = str(ransev.title)
In [939]:
rgdatit
Out[939]:
In [940]:
#rd.get_top
In [941]:
linkdict = {}
In [942]:
ady = r.get_subreddit('artcontroldrawsyou')
In [943]:
comrgd = rgdatit + ' ' + rgdaturo
In [944]:
loctime = time.localtime()
In [945]:
loctime.tm_mday
Out[945]:
In [946]:
loctime.tm_mon
Out[946]:
In [947]:
thedat = (str(loctime.tm_mday) + '/' + str(loctime.tm_mon))
In [948]:
thedat
Out[948]:
In [949]:
mixtut = (thedat + sutit + rgdautoz)
In [950]:
loctime
Out[950]:
In [951]:
#ady.submit(mixtut , (rgdaqwew, comrgd))
In [952]:
'''for newa in rdnew:
#rint newa.url
print len(newa)
htmstr = (str(newa.title) + '<a href="' +
str(newa.url) +
'"><img class="aligncenter size-large wp-image-5723" alt="' +
str(newa.author) +
'" src="' +
str(newa.url) +
'" /></a>')
#ophtml.write(htmstr)
#ady.submit(('[RGD]' + newa.author), newa.url)
print newa.author
#print newa.media
ophtml.write(htmstr)
print newa.selftext
print newa.url
print newa.num_comments
linkdict.update({str(newa.author): str(newa.url)})
'''
Out[952]:
In [953]:
#print str(newa.title)
In [954]:
import json
In [955]:
newzjson = json.dumps(linkdict)
In [956]:
#newzjson
In [956]:
In [957]:
rmine = r.get_redditor('itwillbemine')
In [958]:
#opest = open('userurl.json', 'r')
#opest.read()
#opest.close()
In [959]:
mincom = rmine.get_comments()
In [960]:
#print mincom
In [961]:
minels = []
In [962]:
dausr = {}
In [963]:
for newa in rdnew:
#rint newa.url
#print newa.author
linkdict.update({str(newa.author): str(newa.url)})
In [964]:
for con in mincom:
#print con.body
minels.append(con)
dausr.update({str(con.id): str(con.body)})
In [965]:
itwillbemine = dominate.document(title='itwillbemine')
In [966]:
with itwillbemine.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with itwillbemine:
with div():
attr(cls='header')
#<img src="smiley.gif" alt="Smiley face" height="42" width="42">
h1('itwillbemine')
img(scr='logo.gif')
h2('go away artcontrol')
p(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
a('about', href='http://brobeur.com/artcontroldrawsyou/about')
a('contact', href='http://brobeur.com/artcontroldrawsyou/contact')
a('blog', href='http://brobeur.com/artcontroldrawsyou/wcmckee.com/wcmckee/output')
with div():
attr(cls='header')
#<img src="smiley.gif" alt="Smiley face" height="42" width="42">
h1('itwillbemine')
p(img(scr='http://brobeur.com/artcontroldrawsyou/logo.gif'))
#for mine in minels:
#h1(mine.author_flair_text())
#p(mine.body)
with div(id='author'):
for tits in titlis:
h3(tits)
with div(id='body').add(p()):
for mine in minels:
#h1(mine.created)
p(mine.body)
print itwillbemine
In [967]:
savmine = open('reddit.html', 'w')
savmine.write(str(itwillbemine))
savmine.close()
In [968]:
noizjson = json.dumps(dausr)
In [969]:
newposts = open('userurl.json', 'a')
newposts.write(newzjson)
print ('file userurl.json updated')
newcomments = open('idcomt.json', 'a')
newcomments.write(noizjson)
print ('user comments updated')
newposts.close()
newcomments.close()
In [970]:
rdusr = str(con.author)
In [971]:
minelsz = []
In [972]:
#for mina in minels:
#print mina.body
# minelsz.append(mina.body)
In [973]:
#minelsz
In [974]:
#mina.body
In [975]:
import feedparser
In [976]:
mcs = feedparser.parse('http://mcsteffen.tumblr.com/rss')
In [977]:
emcs = mcs['entries']
In [978]:
for em in emcs:
print em
In [979]:
tumlis = []
In [980]:
for em in emcs:
tumlis.append((em['summary_detail']['value']))
In [981]:
tumlis
Out[981]:
In [982]:
contactpage = dominate.document(title='contact')
In [983]:
with contactpage.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with contactpage:
with div():
attr(cls='top')
#<img src="smiley.gif" alt="Smiley face" height="42" width="42">
h1('artcontroldrawsyou!')
img(scr='logo.gif')
h2('go away artcontrol')
p(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
a('about', href='http://brobeur.com/artcontroldrawsyou/about')
a('contact', href='http://brobeur.com/artcontroldrawsyou/contact')
a('blog', href='http://brobeur.com/artcontroldrawsyou/wcmckee.com/wcmckee/output')
with div():
attr(cls='header')
#<img src="smiley.gif" alt="Smiley face" height="42" width="42">
h1('contact')
p('email: will@artcontrol.me twitter: art_control')
p('Recent comments from itwillbemine:')
#for mine in minels:
#h1(mine.author_flair_text())
#p(mine.body)
# with div(id='author'):
# for tum in tumlis:
# p(tum)
with div(id='body'):
for mine in minels:
#h1(mine.created)
li(mine.body)
print contactpage
In [984]:
os.chdir('contact')
In [985]:
savcon = open('index.html', 'w')
savcon.write(str(contactpage))
savcon.close()
In [986]:
dirdir = os.chdir('/var/www/artcontroldrawsyou')
In [987]:
dirdir
In [988]:
aboutpage = dominate.document(title='about')
with aboutpage.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with aboutpage:
with div():
attr(cls='header')
#<img src="smiley.gif" alt="Smiley face" height="42" width="42">
h1('artcontroldrawsyou!')
img(scr='logo.gif')
h2('go away artcontrol')
p(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
a('about', href='https://brobeur.com/artcontroldrawsyou/about')
a('contact', href='http://brobeur.com/artcontroldrawsyou/contact')
a('blog', href='http://brobeur.com/artcontroldrawsyou/wcmckee.com/wcmckee/output')
with div():
attr(cls='header')
#<img src="smiley.gif" alt="Smiley face" height="42" width="42">
h1('about')
p('artcontroldrawsyou is a website that takes RedditGetsDrawn data and posts it here.')
p('artcontrol is not allowed to submit artwork to redditgetsdrawn so this was created')
#for mine in minels:
#h1(mine.author_flair_text())
#p(mine.body)
'''with div(id='author'):
for tits in titlis:
h3(tits)
with div(id='body').add(p()):
for mine in minels:
#h1(mine.created)
p(mine.body)
'''
print aboutpage
In [989]:
os.chdir('about')
In [990]:
aboucr = open('index.html', 'w')
aboucr.write(str(aboutpage))
aboucr.close()
In [991]:
os.chdir('/var/www/artcontroldrawsyou/')
In [991]:
In [991]:
In [991]:
In [898]:
In [898]:
In [ ]: