GotDrawn
Updating GetsDrawnDotCom with title feature.
Taking getsdrawndotcom code and adding in features such as comments. Getting rid of folder structure.
In [159]:
In [217]:
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 [217]:
In [217]:
In [217]:
In [217]:
In [218]:
gotdrndir = ('/home/wcmckee/gotdrawn/imgs')
In [220]:
r = praw.Reddit(user_agent='getsdrawndotcom')
In [221]:
fulcom = []
fuldic = dict()
In [222]:
getrn = r.get_subreddit('redditgetsdrawn')
In [223]:
rnew = getrn.get_new()
In [224]:
for rnc in rnew:
fulcom.append(rnc)
In [225]:
artes = arrow.utcnow()
In [226]:
yrpath = artes.strftime('%Y')
In [226]:
In [227]:
mntpath = artes.strftime('%m')
In [228]:
dapth = artes.strftime('%d')
In [229]:
if os.path.isdir(gotdrndir) == True:
print 'its true'
else:
print 'its false'
os.mkdir(gotdrndir)
In [230]:
imgszpath = (gotdrndir)
yrzpat = (imgszpath + '/' + yrpath)
mntzpat = (yrzpat + '/' + mntpath)
datzpat = (mntzpat + '/' + dapth)
In [230]:
In [231]:
imgszpath
Out[231]:
In [265]:
dayform = ('/imgs/' + yrpath + '/' + mntpath + '/' + dapth)
In [233]:
dayform
Out[233]:
In [233]:
In [234]:
if os.path.isdir(yrzpat) == True:
print 'its true'
else:
print 'its false'
os.mkdir(yrzpat)
In [235]:
if os.path.isdir(mntzpat) == True:
print 'its true'
else:
print 'its false'
os.mkdir(mntzpat)
In [236]:
if os.path.isdir(datzpat) == True:
print 'its true'
else:
print 'its false'
os.mkdir(datzpat)
In [237]:
datzpat
Out[237]:
In [237]:
In [237]:
In [238]:
mntzpat
Out[238]:
In [239]:
datzpat
Out[239]:
In [239]:
In [239]:
In [239]:
In [240]:
if os.path.isdir(yrpath) == True:
print 'its true'
else:
print 'its false'
os.mkdir(yrpath)
In [241]:
#mthzpath = (yrzpat + '/' +
In [242]:
#if os.path(
In [243]:
print artes.date()
In [244]:
print artes.time()
In [245]:
dati = artes.datetime
In [246]:
#Random logo from logo folder.
#5 to choose from. import random, random choice out of a list
In [247]:
import random
In [248]:
imglis = ['img1', 'img2', 'img3', 'img4', 'img0']
In [249]:
random.choice(imglis)
Out[249]:
In [250]:
os.listdir('/home/wcmckee/gotdrawn/logo')
Out[250]:
In [251]:
import PIL
In [252]:
imed = PIL
In [253]:
imed.PILLOW_VERSION
Out[253]:
In [254]:
#import pillow
In [255]:
os.chdir('/home/wcmckee/gotdrawn/')
In [266]:
imlocdir = (dayform + '/' + str(flc.author) + '-reference.png')
In [267]:
imlocdir
Out[267]:
In [257]:
In [268]:
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 [269]:
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 [270]:
fertz = datzpat + '/'
In [271]:
fertz
Out[271]:
In [272]:
print doc
In [273]:
os.chdir(fertz)
In [274]:
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 [ ]: