GotDrawn
Updating GetsDrawnDotCom with title feature.
Taking getsdrawndotcom code and adding in features such as comments. Getting rid of folder structure.
In [159]:
In [160]:
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 [160]:
In [161]:
gotdrndir = ('/home/wcmckee/gotdrawn/imgs')
In [162]:
r = praw.Reddit(user_agent='getsdrawndotcom')
In [163]:
fulcom = []
fuldic = dict()
In [164]:
getrn = r.get_subreddit('redditgetsdrawn')
In [165]:
rnew = getrn.get_new()
In [166]:
for rnc in rnew:
fulcom.append(rnc)
In [167]:
artes = arrow.utcnow()
In [168]:
yrpath = artes.strftime('%Y')
In [168]:
In [169]:
mntpath = artes.strftime('%m')
In [170]:
dapth = artes.strftime('%d')
In [171]:
if os.path.isdir(gotdrndir) == True:
print 'its true'
else:
print 'its false'
os.mkdir(gotdrndir)
In [180]:
imgszpath = (gotdrndir)
yrzpat = (imgszpath + '/' + yrpath)
mntzpat = (yrzpat + '/' + mntpath)
datzpat = (mntzpat + '/' + dapth)
In [180]:
In [181]:
imgszpath
Out[181]:
In [182]:
dayform = ('imgs/' + yrpath + '/' + mntpath + '/' + dapth)
In [183]:
dayform
Out[183]:
In [183]:
In [184]:
if os.path.isdir(yrzpat) == True:
print 'its true'
else:
print 'its false'
os.mkdir(yrzpat)
In [185]:
if os.path.isdir(mntzpat) == True:
print 'its true'
else:
print 'its false'
os.mkdir(mntzpat)
In [186]:
if os.path.isdir(datzpat) == True:
print 'its true'
else:
print 'its false'
os.mkdir(datzpat)
In [187]:
datzpat
Out[187]:
In [187]:
In [187]:
In [188]:
mntzpat
Out[188]:
In [189]:
datzpat
Out[189]:
In [189]:
In [189]:
In [189]:
In [190]:
if os.path.isdir(yrpath) == True:
print 'its true'
else:
print 'its false'
os.mkdir(yrpath)
In [191]:
#mthzpath = (yrzpat + '/' +
In [192]:
#if os.path(
In [192]:
In [193]:
print artes.date()
In [194]:
print artes.time()
In [195]:
dati = artes.datetime
In [196]:
#Random logo from logo folder.
#5 to choose from. import random, random choice out of a list
In [197]:
import random
In [198]:
imglis = ['img1', 'img2', 'img3', 'img4', 'img0']
In [199]:
random.choice(imglis)
Out[199]:
In [200]:
os.listdir('/home/wcmckee/gotdrawn/logo')
Out[200]:
In [201]:
import PIL
In [202]:
imed = PIL
In [203]:
imed.PILLOW_VERSION
Out[203]:
In [204]:
#import pillow
In [204]:
In [204]:
In [204]:
In [205]:
os.chdir('/home/wcmckee/gotdrawn/')
In [206]:
imlocdir = (dayform + '/' + str(flc.author) + '-reference.png')
In [207]:
imlocdir
Out[207]:
In [207]:
In [208]:
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 [209]:
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 [ ]:
In [ ]:
In [210]:
fertz = datzpat + '/'
In [211]:
fertz
Out[211]:
In [109]:
print doc
In [212]:
os.chdir(fertz)
In [ ]:
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
In [58]:
flcz.author
flcz.body
Out[58]:
In [ ]:
In [ ]:
In [ ]: