make rst

Create GetsDrawn post of images


In [2]:
import requests
import bs4
import json
import arrow
import praw
import os

import ntpath

In [3]:
r = praw.Reddit(user_agent='getsdrawndotcom')

In [4]:
rsubred = r.get_subreddit('redditgetsdrawn')

In [5]:
rsunewq = rsubred.get_new()

In [6]:
#for rsubcom in rsubred.get_comments():
#    print (rsubcom)
    #if (rsubcom.author) != 'ItWillBeMine':
    #    print (rsubcom)
    #    print (rsubcom.author)
    
    #answer != 'hi':   # not equal
    #   print "no hi"
    #print (rsubcom.author)

In [7]:
arnowz = arrow.now()

In [8]:
ardat = arnowz.date()

In [9]:
str(ardat)


Out[9]:
'2015-08-13'

In [10]:
artim = arnowz.time()

In [11]:
regetd = requests.get('http://getsdrawn.com')

In [12]:
#requgetdrn = open('/home/wcmckee/getsdrawndotcom/index.html', 'r')

In [13]:
bst = bs4.BeautifulSoup(regetd.text)

In [49]:
bst


Out[49]:
<!DOCTYPE html>
<html>
<head>
<title>GetsDrawn</title>
<link href="style.css" rel="stylesheet"/><script src="script.js" type="text/javascript"></script>
</head><body><div class="header">
<h1>GetsDrawn</h1>
<p>
<img src="imgs/getsdrawn-bw.png"/>
</p>
<h1>Updated Thu, 13 Aug 2015 11:00:04 +0000</h1>
<p>GetsDrawn - Recent reference images uploaded to r/RedditGetsDrawn
</p>
<p></p>
</div>
<div id="body">
<ol>
<p>
<img src="imgs/15/08/13/reference/Zoeamae-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/Zoeamae-reference.png">imgs/15/08/13/reference/Zoeamae-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/kkoool-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/kkoool-reference.png">imgs/15/08/13/reference/kkoool-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/MattChenery11-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/MattChenery11-reference.png">imgs/15/08/13/reference/MattChenery11-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/DizKord-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/DizKord-reference.png">imgs/15/08/13/reference/DizKord-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/KegelatorChariot-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/KegelatorChariot-reference.png">imgs/15/08/13/reference/KegelatorChariot-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/TheSanelli-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/TheSanelli-reference.png">imgs/15/08/13/reference/TheSanelli-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/phallustrious-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/phallustrious-reference.png">imgs/15/08/13/reference/phallustrious-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/Anotherelephant-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/Anotherelephant-reference.png">imgs/15/08/13/reference/Anotherelephant-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/brookebaty12-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/brookebaty12-reference.png">imgs/15/08/13/reference/brookebaty12-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/lawlore-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/lawlore-reference.png">imgs/15/08/13/reference/lawlore-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/Jmertelj-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/Jmertelj-reference.png">imgs/15/08/13/reference/Jmertelj-reference.png</a>
</p>
<p>
<img src="imgs/15/08/13/reference/Napim8-reference.png"/>
</p>
<p>
</p><p>
<a href="http://getsdrawn.com/imgs/15/08/13/reference/Napim8-reference.png">imgs/15/08/13/reference/Napim8-reference.png</a>
</p>
</ol>
</div>
<div class="body">
<p>GetsDrawn is open source</p>
<p>
</p><p>
<a href="https://github.com/getsdrawn/">getsdrawn - github</a>
</p>
<p>
</p><p>
<a href="https://reddit.com/r/redditgetsdrawn">RedditGetsDrawn</a>
</p>
</div>
</body></html>

In [14]:
#requgetdrn.close()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-14-24c4deba2012> in <module>()
----> 1 requgetdrn.close()

NameError: name 'requgetdrn' is not defined

In [ ]:
bst.find('a')

In [21]:
alimg = bst.find_all('a')
    #print(bs)

In [92]:
alinkl = list()

In [93]:
namref = list()

In [97]:
import ntpath

In [ ]:


In [104]:
for ali in alimg:
    ntpa = (ntpath.basename(ali.attrs['href'][:-14]))
    print (ntpa)
    urlink = (ali.attrs['href'])
    print (urlink)
    #Need to remove https://github.com and https://reddit.com urls from the lit
    #print (ali.attrs['href'])
    alinkl.append((ali.attrs['href']))
    namref.append((ali.attrs['href'][:-4]))
    
    
    mkmeta = open('/home/wcmckee/github/getsdrawnblog/posts/' +  ntpa + '.rst', 'w')
    mkmeta.write('.. image:: ' + urlink)
    mkmeta.close()
    
    opmeta = open('/home/wcmckee/github/getsdrawnblog/posts/' + ntpa + '.meta', 'w')
    
    opmeta.write((ntpa + '\n' + ntpa + '\n' + str(ardat) + ' ' + str(artim)))
    
    #opmeta.close()
    
    #print(ali.text)


Zoeamae
http://getsdrawn.com/imgs/15/08/13/reference/Zoeamae-reference.png
kkoool
http://getsdrawn.com/imgs/15/08/13/reference/kkoool-reference.png
MattChenery11
http://getsdrawn.com/imgs/15/08/13/reference/MattChenery11-reference.png
DizKord
http://getsdrawn.com/imgs/15/08/13/reference/DizKord-reference.png
KegelatorChariot
http://getsdrawn.com/imgs/15/08/13/reference/KegelatorChariot-reference.png
TheSanelli
http://getsdrawn.com/imgs/15/08/13/reference/TheSanelli-reference.png
phallustrious
http://getsdrawn.com/imgs/15/08/13/reference/phallustrious-reference.png
Anotherelephant
http://getsdrawn.com/imgs/15/08/13/reference/Anotherelephant-reference.png
brookebaty12
http://getsdrawn.com/imgs/15/08/13/reference/brookebaty12-reference.png
lawlore
http://getsdrawn.com/imgs/15/08/13/reference/lawlore-reference.png
Jmertelj
http://getsdrawn.com/imgs/15/08/13/reference/Jmertelj-reference.png
Napim8
http://getsdrawn.com/imgs/15/08/13/reference/Napim8-reference.png
github.
https://github.com/getsdrawn/
r
https://reddit.com/r/redditgetsdrawn
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/r.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/Zoeamae.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/kkoool.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/MattChenery11.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/DizKord.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/KegelatorChariot.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/TheSanelli.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/phallustrious.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/Anotherelephant.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/brookebaty12.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/lawlore.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/Jmertelj.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/Napim8.meta' mode='w' encoding='UTF-8'>
/usr/local/lib/python3.4/dist-packages/IPython/kernel/__main__.py:16: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/wcmckee/github/getsdrawnblog/posts/github..meta' mode='w' encoding='UTF-8'>

In [ ]:
ntpa = (ntpath.basename(ali.text)[:-14])
    print (ntpa)

In [91]:
namref


Out[91]:
['http://getsdrawn.com/imgs/15/08/13/reference/Zoeamae-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/kkoool-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/MattChenery11-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/DizKord-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/KegelatorChariot-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/TheSanelli-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/phallustrious-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/Anotherelephant-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/brookebaty12-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/lawlore-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/Jmertelj-reference.p',
 'http://getsdrawn.com/imgs/15/08/13/reference/Napim8-reference.p',
 'https://github.com/getsdraw',
 'https://reddit.com/r/redditgetsdra']

In [ ]:


In [ ]:
'''
for ali in alimg:
    ntpa = (ntpath.basename(ali.text)[:-14])
    print (ntpa)

    mkmeta = open('/home/wcmckee/github/getsdrawnblog/posts/' +  ntpa + '.rst', 'w')

    mkmeta.write('.. |' + ntpa + '| image:: ' + ali.text)
    
    mkmeta.close()
    
    mkmeta = open('/home/wcmckee/github/getsdrawnblog/posts/' + ntpa + '.meta', 'w')

    mkmeta.write(ntpa + '\n' + ntpa + '\n' + str(ardat) + ' ' + str(artim))

    mkmeta.close()
'''

In [ ]:


In [ ]:
for rsunw in rsunewq:
    #print (rsunw.author)
    #print (rsunw.author)
    mkmeta = open('/home/wcmckee/github/getsdrawnblog/posts/' +  str(rsunw.author) + '.rst', 'w')
    mkmeta.write('.. image:: ' + rsunw.url)
    mkmeta.close()
    
    opmeta = open('/home/wcmckee/github/getsdrawnblog/posts/' + str(rsunw.author) + '.meta', 'w')
    
    opmeta.write((str(rsunw.author) + '\n' + str(rsunw.author) + '\n' + str(ardat) + ' ' + str(artim)))
    
    opmeta.close()

In [15]:
import os

In [16]:
os.chdir('/home/wcmckee/github/getsdrawnblog/')

In [17]:
os.system('nikola build')


Out[17]:
0

In [ ]: