BroBeurKids Nikola

This script deals with creating data for BroBeurKids/wcmckee Nikola site.

The directory to look at is brobeurkidsdotcom/posts or folder

wcmckee.com /posts

/github folders are scanned with the input for folders. It's basically a search for notebook, then turn notebook into a blog posts.

Arrow is used to generate the date (YR/MONTH/DAY), and time(HR : MIN: SEC)

This is where ipynb files are kept.

This script generates the .meta files needed.

The meta file is called the same as the ipynb. It also contains the slug and title, and date. The date is collected by looking at the save date of the ipynb.

Create preconfig files. A posts folder that one item is published. Depending on prepost folder deturms the post folder it's moved to. Sequale and post certain times a day.

This script creates a blog post and saves it in posts folder along with the .meta file for it. Config file for the script. Specify a list of blog names. Reads a json file that contains: blog name (school name), author (input username), twitter config dir, domain name (school name - space and crap),

Do login/logout via blog post.

Title should accept spaces - slug should be edited to remove space and replace with -


In [1]:
import os
import getpass
from walkdir import filtered_walk, dir_paths, all_paths, file_paths
import arrow
#import nikola
#from TwitterFollowBot import TwitterBot

In [135]:
raw = arrow.now()

In [136]:
def returntime():
    return raw.strftime('%H:%M:%S')

In [137]:
yraw = raw.strftime("%Y")
mntaw = raw.strftime("%m")
dytaw = raw.strftime("%d")
#gmtz.strftime("%Y")

In [138]:
fulda = yraw + '/' + mntaw + '/' + dytaw

In [139]:
fultim = fulda + ' ' + returntime()

In [140]:
datim = str(raw.datetime)

In [146]:
fultim


Out[146]:
'2015/10/09 13:28:13'

In [ ]:


In [ ]:


In [7]:
#fultim

In [8]:
#gtur = getpass.getuser()

In [9]:
#lisbbkn = os.listdir('/home/' + gtur + '/brobeurkidsdotcom/posts')

In [10]:
#lisbbkn

In [11]:
#for lisb in lisbbkn:
#    if '.ipynb' in lisb:
#        print lisb

In [12]:
#Name of notebook you want to turn into a blog
#Could check the folder (walkdir) for files not 
#in the wcmckee.com posts folder.
#Tags. Modules used. 
#Look at the file and extract out modules imported,
#using these as tags.

In [83]:
podir = input('blog dir: ')


blog dir: /home/wcmckee/writersdenhamilton/

In [84]:
nbog = input('Name of file to blog: ')


Name of file to blog: sherlock

In [85]:
etnam = input('Extension of file to blog: ')


Extension of file to blog: .rst

In [86]:
tagmak = input('post tags: ')


post tags: notes

In [87]:
catmak = input('post author: ')


post author: wcmckee

In [149]:
rstme = ('.. title: ' + nbog + ' \n' + '.. slug: ' + nbog + ' \n' + '.. date: ' + fultim + ' \n' + '.. author: ' + catmak)

In [ ]:


In [89]:
#pear = input('path to search: ')

In [90]:
jsve = dict()

In [91]:
nbog + etnam


Out[91]:
'sherlock.rst'

In [92]:
#Write the blog post
#Ask to write content or publish 
writecont = input('Write content? y/N ')
if 'y' in writecont:
    contenmak = input('content: ')

else:
    #search or manually locate fil.
    pear = input('path to search: y/N')
    if 'y' in pear:
        files = file_paths(filtered_walk(pear, depth=100, included_files=[nbog + etnam]))
        for fil in files:
            print (fil)
            jsve.update({'filefound' : fil})
    else:
        patlim = input('path of file: ')
        jsve.update({'filefound' : patlim + nbog + etnam})


Write content? y/N 
path to search: y/N
path of file: /home/wcmckee/bbpost/

In [93]:
#fil

In [94]:
#add extra tags in

In [95]:
jsve


Out[95]:
{'filefound': '/home/wcmckee/bbpost/sherlock.rst'}

In [96]:
#lastbit = contenmak[:50]

In [97]:
#contenmak[-50:]

In [98]:
#sampb = lastbit + '... ' + contenmak[-50:]

In [99]:
#sampb

In [ ]:


In [100]:
#savewhere = input('dir to save post: ')

In [101]:
my_list = tagmak.split(",")

In [102]:
my_list


Out[102]:
['notes']

In [103]:
hashtag = list()

In [104]:
for myl in my_list:
    #print ('#' + myl.replace(' ', ''))
    hashtag.append(('#' + myl.replace(' ', '')))

In [105]:
#bro_bot = TwitterBot('/home/wcmckee/wcmnot/wcmckee-notebook/config.txt')
#bro_ot = TwitterBot(podir + '/config.txt')

In [106]:
#for has in hashtag:
#    print (has)
#    bro_bot.auto_follow(has, count=1)

In [107]:
endstring = ''
for s in hashtag:
    endstring += s + ' '

In [108]:
endstring


Out[108]:
'#notes '

In [ ]:


In [109]:
jsve.update({'filename' : nbog + etnam, 'tags' : tagmak, 'datetime' : datim})

In [110]:
#jsve.update({})

In [111]:
jsve


Out[111]:
{'datetime': '2015-10-09 00:07:13.070409+00:00',
 'filefound': '/home/wcmckee/bbpost/sherlock.rst',
 'filename': 'sherlock.rst',
 'tags': 'notes'}

In [112]:
#Search for blog through folders.

In [113]:
#files = file_paths(filtered_walk(pear, depth=100, included_files=[nbog + etnam]))

In [114]:
#print files

In [115]:
#for fil in files:
#    print (fil)
#    jsve.update({'filefound' : fil})

In [116]:
#jsve['filefound']

In [117]:
#opblog = ('/home/wcmckee/github/')

In [118]:
#podir = ('/home/wcmckee/github/wcmckee.com/posts/')

In [119]:
jsve.update({'blogdir' : podir})

In [120]:
postsdir = podir + ('/posts/' )

In [121]:
#os.system('cp ' + jsve['filefound'] + ' ' + postsdir)

In [122]:
#for fie in files:
    #print fie
    #print (fie)
    #print ('Copy ' + fie + ' to ' + postsdir)
    #os.system('cp ' + fie + ' ' + postsdir)

In [123]:
jsve


Out[123]:
{'blogdir': '/home/wcmckee/writersdenhamilton/',
 'datetime': '2015-10-09 00:07:13.070409+00:00',
 'filefound': '/home/wcmckee/bbpost/sherlock.rst',
 'filename': 'sherlock.rst',
 'tags': 'notes'}

In [ ]:


In [124]:
os.system('cp ' + jsve['filefound'] + ' ' + postsdir)


Out[124]:
0

In [125]:
if 'y' in writecont:
    oprst = open(podir + '/posts/' + nbog + etnam, 'w')
    oprst.write(contenmak)
    oprst.close()
else:
    os.system('cp ' + jsve['filefound'] + ' ' + postsdir)

In [150]:
opeza = open(podir + '/posts/' + nbog + '.meta', 'w')
opeza.write(rstme)

opeza.close()

In [127]:
#print (podir + '/posts/' + nbog + '.meta')

In [128]:
#os.chdir(podir)
#os.system('nikola build')

In [129]:
#os.system('rsync -azP ' + postsdir + ' ' + 'wcmckee@brobeur.com:/home/wcmckee/bb/blog/posts')

In [130]:
#bro_bot.search_tweets(ndstring)

In [131]:
#bro_bot.send_tweet(nbog + ' ' + endstring + ' http://brobeur.com/blog/output/posts/' + nbog + '.html')

In [ ]:


In [ ]:


In [ ]: