drawnuseconfig

Drawn Use Config

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]:
['/home/wcmckee/gotdrawn/config.cfg']
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')
Not going to output folders
In [49]:
if outputfile == True:
    print ('Going to output filename date')
else:
    print ('Not going to output filename date')
Not going to output filename date
In [50]:
str(outputfile)
Out[50]:
'False'
In [51]:
outputfile
#if this is true it just makes the files with date in 
#filename
Out[51]:
u'False'
In [52]:
subredlookup
Out[52]:
u'redditgetsdrawn'
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)
its true
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
1 :: I was hoping you fine people would draw me and my New Kids on the Block ...
1 :: This is my grandma at her 90th birthday party! Would anyone like to draw...
1 :: My friends are engaged! They were so overjoyed with love. I'd like to gi...
1 :: My big sis' birthday is coming up.. And I know she loves this photo of u...
1 :: Could you draw my best friend and I hanging out by the lake? Weather mad...
8 :: Lovely photo of my sister that a good friend took :3
5 :: Hey guys! I've been losing weight and can finally fit into this awesome ...
1 :: Could someone draw my amazing baby momma & my gorgeous daughter? Any...
1 :: Wife snapped this photo of me on the way to the Library. Whatcha think, ...
4 :: I'd love a drawing of my son! Any takers on this little man?
2 :: This is my best friend in the world and her birthday is coming up. It wo...
4 :: HEy guys! Just remembered this subreddit is a (awesome!)thing. Mind draw...
5 :: Can someone draw my picture? This picture made me feel beautiful. :)
0 :: Hello RGD! Our 2 year anniversary is coming up at the beginning of April...
2 :: Would anyone be willing to draw my two favorite creatures in the world, ...
0 :: Hi! Could anybody paint or draw a picture of my mother and I at the Brav...
6 :: Here's me, trying to look at the eclipse in the UK. It would be cool to ...
1 :: Would anybody like to draw me as a super hero, or just as my super aweso...
6 :: I love this picture of my sisters and I could anyone draw us?
3 :: Please draw my niece and nephew
6 :: Anyone care to draw me? :) Sorry for the sepia, I can't find the original
6 :: Hey guys, first time here, that's my gf's favorite picture of me, would ...
4 :: Could reddit help me out? This is a good friend of mine wanting to get d...
0 :: Can sombody please draw my beautiful wife driving? I'd love to surprise ...
17 :: I've always adored this photo of my dad and I. Would love to see what y...
In [62]:
fulldirz = gtsdrndir + '/'
In [71]:
fulldirz
Out[71]:
u'/home/wcmckee/testingdir/'
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]:
u'/home/wcmckee/testingdir/imgs/2015'
In [ ]:
 
In [82]:
mntpath = artes.strftime('%m')
In [83]:
fullmntz = fullyrz + '/' + mntpath
In [84]:
fullmntz
Out[84]:
u'/home/wcmckee/testingdir/imgs/2015/03'
In [ ]:
 
In [85]:
dapth = artes.strftime('%d')
In [86]:
fulldayz = fullmntz + '/' + dapth
In [91]:
fulldirza = fulldayz + '/'
In [92]:
fulldirza
Out[92]:
u'/home/wcmckee/testingdir/imgs/2015/03/21/'
In [105]:
fuldaya = yrpath + '/' + mntpath + '/' + dapth
In [69]:
if os.path.isdir(fulldirz) == True:
    print 'its true'
else:
    print 'its false'
    os.mkdir(fulldirz)
its true
In [78]:
if os.path.isdir(fullimgz) == True:
    print ('its true')
else:
    print ('its false')
    os.mkdir(fullimgz)
its false
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)
its false
its false
its false
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
http://i.imgur.com/0Y4X05A.jpg
http://i.imgur.com/qs2sQSF.jpg
http://i.imgur.com/CcXe9Vf.jpg
http://i.imgur.com/DLla74g.jpg
http://i.imgur.com/mVrm6kf.jpg
http://i.imgur.com/kLUsVpC.jpg
http://i.imgur.com/RESKejj.jpg
http://i.imgur.com/4HgtOGO.jpg
http://i.imgur.com/lShCJ0S.jpg
http://i.imgur.com/d12DNT3.jpg
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]:
'2015/03/21'
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
<!DOCTYPE html>
<html>
  <head>
    <title>redditgetsdrawn</title>
    <link href="style.css" rel="stylesheet"><script src="script.js" type="text/javascript"></script>
    <div class="header">
      <h1>redditgetsdrawn</h1>
      <p>
        <img src="/imgs/getsdrawn-bw.png">
      </p>
      <h1>Updated 2015-03-21 00:56:54.295874+00:00</h1>
    </div>
  </head>
  <body>
    <div id="body">
      <ol>
        <p>
          <img src="imgs/2015/03/21/pointlesspanda-reference.png">
        </p>
        <p>imgs/2015/03/21/pointlesspanda-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/kikiwest-reference.png">
        </p>
        <p>imgs/2015/03/21/kikiwest-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/adventurousnails-reference.png">
        </p>
        <p>imgs/2015/03/21/adventurousnails-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/petrichor182-reference.png">
        </p>
        <p>imgs/2015/03/21/petrichor182-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/mmmmpork-reference.png">
        </p>
        <p>imgs/2015/03/21/mmmmpork-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/roslynd_a-reference.png">
        </p>
        <p>imgs/2015/03/21/roslynd_a-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/bigmanute-reference.png">
        </p>
        <p>imgs/2015/03/21/bigmanute-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/luger718-reference.png">
        </p>
        <p>imgs/2015/03/21/luger718-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/I_am_Bearstronaut-reference.png">
        </p>
        <p>imgs/2015/03/21/I_am_Bearstronaut-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/kellerman72-reference.png">
        </p>
        <p>imgs/2015/03/21/kellerman72-reference.png</p>
      </ol>
    </div>
  </body>
</html>
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
<!DOCTYPE html>
<html>
  <head>
    <title>redditgetsdrawn</title>
    <link href="style.css" rel="stylesheet"><script src="script.js" type="text/javascript"></script>
    <div class="header">
      <h1>redditgetsdrawn</h1>
      <p>
        <img src="/imgs/getsdrawn-bw.png">
      </p>
      <h1>Updated 2015-03-21 00:56:54.295874+00:00</h1>
    </div>
  </head>
  <body>
    <div id="body">
      <ol>
        <p>
          <img src="imgs/2015/03/21/pointlesspanda-reference.png">
        </p>
        <p>imgs/2015/03/21/pointlesspanda-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/kikiwest-reference.png">
        </p>
        <p>imgs/2015/03/21/kikiwest-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/adventurousnails-reference.png">
        </p>
        <p>imgs/2015/03/21/adventurousnails-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/petrichor182-reference.png">
        </p>
        <p>imgs/2015/03/21/petrichor182-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/mmmmpork-reference.png">
        </p>
        <p>imgs/2015/03/21/mmmmpork-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/roslynd_a-reference.png">
        </p>
        <p>imgs/2015/03/21/roslynd_a-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/bigmanute-reference.png">
        </p>
        <p>imgs/2015/03/21/bigmanute-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/luger718-reference.png">
        </p>
        <p>imgs/2015/03/21/luger718-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/I_am_Bearstronaut-reference.png">
        </p>
        <p>imgs/2015/03/21/I_am_Bearstronaut-reference.png</p>
        <p>
          <img src="imgs/2015/03/21/kellerman72-reference.png">
        </p>
        <p>imgs/2015/03/21/kellerman72-reference.png</p>
      </ol>
    </div>
  </body>
</html>
In [146]:
 
In [ ]:
 

Comments

Comments powered by Disqus