This script uses the config file created with configdraw to run the getsdrawndotcom script.
This script must open and read the config file created with configdraw. It then uses the var in the config file to run the getsdrawndotcom script
In [65]:
import configparser
import os
import requests
from bs4 import BeautifulSoup
import re
import json
import time
import praw
import dominate
from dominate.tags import *
import arrow
import getpass
import shutil
In [40]:
confidg = configparser.RawConfigParser()
In [41]:
confidg.read('/home/wcmckee/gotdrawn/config.cfg')
Out[41]:
In [42]:
subredlookup = confidg.get('subredinfo', 'subbreddit')
In [43]:
dirpathz = confidg.get('subredinfo', 'dirpath')
In [44]:
outputfold = confidg.get('subredinfo', 'outputfolder')
In [45]:
outputfile = confidg.get('subredinfo', 'outputfile')
In [46]:
outfoldstr = str(outputfold)
#If this is true - makes/checks for date folders.
In [47]:
#The value is True but it's not working.
In [48]:
if outfoldstr == True:
print ('Going to output folders for imgs')
else:
print ('Not going to output folders')
In [49]:
if outputfile == True:
print ('Going to output filename date')
else:
print ('Not going to output filename date')
In [50]:
str(outputfile)
Out[50]:
In [51]:
outputfile
#if this is true it just makes the files with date in
#filename
Out[51]:
In [52]:
subredlookup
Out[52]:
In [53]:
hosnam = getpass.getuser()
gtsdrndir = ('/home/' + hosnam + '/' + dirpathz)
In [54]:
if os.path.isdir(gtsdrndir) == True:
print 'its true'
else:
print 'its false'
os.mkdir(gtsdrndir)
In [55]:
r = praw.Reddit(user_agent='getsdrawndotcom')
In [56]:
getnewr = r.get_subreddit(subredlookup)
In [57]:
rdnew = getnewr.get_new()
In [58]:
lisrgc = []
lisauth = []
In [59]:
for uz in rdnew:
#print uz
lisrgc.append(uz)
In [60]:
gtdrndic = dict()
In [61]:
for itzza in lisrgc:
print itzza
In [62]:
fulldirz = gtsdrndir + '/'
In [71]:
fulldirz
Out[71]:
In [77]:
fullimgz = fulldirz + 'imgs'
In [72]:
artes = arrow.utcnow()
In [73]:
yrpath = artes.strftime('%Y')
In [79]:
fullyrz = fullimgz + '/' + yrpath
In [81]:
fullyrz
Out[81]:
In [ ]:
In [82]:
mntpath = artes.strftime('%m')
In [83]:
fullmntz = fullyrz + '/' + mntpath
In [84]:
fullmntz
Out[84]:
In [ ]:
In [85]:
dapth = artes.strftime('%d')
In [86]:
fulldayz = fullmntz + '/' + dapth
In [91]:
fulldirza = fulldayz + '/'
In [92]:
fulldirza
Out[92]:
In [105]:
fuldaya = yrpath + '/' + mntpath + '/' + dapth
In [69]:
if os.path.isdir(fulldirz) == True:
print 'its true'
else:
print 'its false'
os.mkdir(fulldirz)
In [78]:
if os.path.isdir(fullimgz) == True:
print ('its true')
else:
print ('its false')
os.mkdir(fullimgz)
In [89]:
if os.path.isdir(fullyrz) == True:
print ('its true')
else:
print ('its false')
os.mkdir(fullyrz)
if os.path.isdir(fullmntz) == True:
print ('its true')
else:
print ('its false')
os.mkdir(fullmntz)
if os.path.isdir(fulldayz) == True:
print ('its true')
else:
print ('its false')
os.mkdir(fulldayz)
In [93]:
for rdz in lisrgc:
(rdz.title)
#a(rdz.url)
if 'http://i.imgur.com' in rdz.url:
#print rdz.url
print (rdz.url)
url = rdz.url
response = requests.get(url, stream=True)
with open(fulldirza + str(rdz.author) + '-reference.png', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
In [95]:
dayphoto = os.listdir(fulldirza)
In [109]:
for dayph in dayphoto:
p(img('imgs/' + fuldaya + '/' + dayph, src= 'imgs/' + fuldaya + '/' + dayph))
In [106]:
p(img('imgs/' + fuldaya + '/' + dayph, src= 'imgs/' + fuldaya + '/' + dayph))
Out[106]:
In [147]:
doc = dominate.document(title=subredlookup)
with doc.head:
link(rel='stylesheet', href='style.css')
script(type ='text/javascript', src='script.js')
#str(str2)
with div():
attr(cls='header')
h1(subredlookup)
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 dayph in dayphoto:
p(h1(dayph.title))
p(img('imgs/' + str(fuldaya + '/' + str(dayph)), src= str('imgs/' + str(fuldaya) + '/' + str(dayph))))
#p(p('imgs/' + str(fuldaya) + '/' + str(dayph))
p(str(('imgs/' + str(fuldaya) + '/' + str(dayph))))
#p(img(flc.url, src = flc.url))
#p((dayph.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 [148]:
print doc
In [149]:
indexsav = open(gtsdrndir + '/index.html', 'w')
#tsdrndir
indexsav.write(str(doc))
In [150]:
indexsav.close()
In [151]:
cat /home/wcmckee/testingdir/index.html
In [146]:
In [ ]: