perform ls on directory looking for most recent rst file change. Gets wordcount, most recent word, date and time of this change.

Record the wordcount in a json object, compare to older json objects and punish or rewards depending on changes.

Tweets during the day of changes.

Creative Commons licence


In [ ]:


In [1]:
import os
import glob
import getpass

In [2]:
theusr = getpass.getuser()

In [5]:
def getRecent():
    return max(glob.iglob('/home/' + theusr + '/git/writersdenhamilton/posts/*.rst'),
                       key=os.path.getctime)

def getPaths():
    return os.path.basename(newest)

def getWords():
    with open(getRecent(), 'r', encoding='utf-8') as infile:
        return infile.read()

def getSplit():
    return getWords()

In [6]:
getRecent()


Out[6]:
'/home/wcm/git/writersdenhamilton/posts/fallofgiants.rst'

In [7]:
getPaths()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-cf2db5925d97> in <module>()
----> 1 getPaths()

<ipython-input-5-d3ffbbd5f5b3> in getPaths()
      4 
      5 def getPaths():
----> 6     return os.path.basename(newest)
      7 
      8 def getWords():

NameError: name 'newest' is not defined

In [9]:
getWords()


Out[9]:
'Fall Of Giants\n\nKen Follett\n\nBook One of The Century Trilogy\n\nCast of Characters \n\nAmerican \n\nDewar Family\n\nSenator Cameron Drwar\nUrsula Drwar, his wife\nGus Drwar, their son\n\nVyalov Family\n\nJosef Vylov, businessman\nLena Vyalov, his wife\nOlga Vyalov, their daughter\n\nOthers\n\nRosa Hellman, journalist\nChuck Dixon, school friend of Gus\'s\nMarga, nightclub singer\nNick Forman, thief\nIlya, thug\nTheo, thug\nNorman Niall, croked accountant\nBrian Hall, union leader \n\nReal historical characters\n\nEnglish and Scottish\n\nFitzherbert Family.\n\nEarl Fitzherbert, called Fitz\nPrincess Elizabeta, called Bea, his wife\nLady Maud Fitzherbert, his sister\nLady Hermia, called Aunt Herm, their poor aunt\nThe Duchess of Sussex, their rich aunt\nGelert, Pyreneam mountain dog\nGrout, Fitz\'s butler\nSanderson, Maud\'s maid\n\nOthers\n\nMildred Perkins, Ethel William\'s lodger\nBernie Leckwith, secretary of the Aldgate branch of the Interpendent Labour Party\nBing Westhampton, Gitz\'s friend \nMarquis of Lowther, "Lowthie," rejected suitor of Maud\n\nAlbert Solman, Fitz\'s man of business \nDr. Greenward, volunteer at the baby clinic\nLord "Johnny" Re\n\n\n\nMany view points, leading up to ww1 and after it. Issue - the length of\nbook. too big. Could if been cut in half - could of been 2 books. \n\nNormally key villan in his book. It isnt key villan. no  cold blooded \nkillers. Multipy political too much political. woman right to vote,\n\nenjoyed characters care about, Billy coal miner from Wales. Innocent young kid,\nend as ww1 vetrium, political,\nWW1. honor the history. why it happened, not biast. everyone view point. \nwell rounded. \n\nResearch 20th centry\n\nKilled so many each other. Our centry. Where we come from.\n1911 welsh mining time. quit school to work.\n\nwhere author comes from. Grandfather went down the pit - like Billy.\n\nsocial divide. money divide. pretend they different. fight, move from \nclasses, fall in love. Class nation divisions. Two familys \n\nSister of Billy, Ethel\nSister of Fitz, Maud\n\nFight for womans rights. Feel deprived. Even upper class was restricted.\nMaud photo captured being arrested by a police officer.\n\n1914, woman 21 not allowed to go anywhere alone. Maud.\n\nRole of Woman. Woman fought political battles. Harsh treated by media \nand police. They won! \n\nmen gave in. woman vote over 30, men over 21. lets be pratible. \npricible. treat equal. split movement.\n\nEvents leading up to ww1. How to tell? Maud fall in love with young \ngerman spy. want to get married. Maud and Walter.\n\nRussian - saving to go to America. Fought in ww1 for russia. men of the \nrevolution.\nOne living american dream. One a revalution in Russia. Grigori and Lev.\n\nGerman invasion of USA. Newspaper. Media quick on haterd on enemys. \nWanted\nto whip up. gone to war no prblem. New weapons. machine guns. made \neverything more terrible. \n'

In [10]:
getSplit()


Out[10]:
'Fall Of Giants\n\nKen Follett\n\nBook One of The Century Trilogy\n\nCast of Characters \n\nAmerican \n\nDewar Family\n\nSenator Cameron Drwar\nUrsula Drwar, his wife\nGus Drwar, their son\n\nVyalov Family\n\nJosef Vylov, businessman\nLena Vyalov, his wife\nOlga Vyalov, their daughter\n\nOthers\n\nRosa Hellman, journalist\nChuck Dixon, school friend of Gus\'s\nMarga, nightclub singer\nNick Forman, thief\nIlya, thug\nTheo, thug\nNorman Niall, croked accountant\nBrian Hall, union leader \n\nReal historical characters\n\nEnglish and Scottish\n\nFitzherbert Family.\n\nEarl Fitzherbert, called Fitz\nPrincess Elizabeta, called Bea, his wife\nLady Maud Fitzherbert, his sister\nLady Hermia, called Aunt Herm, their poor aunt\nThe Duchess of Sussex, their rich aunt\nGelert, Pyreneam mountain dog\nGrout, Fitz\'s butler\nSanderson, Maud\'s maid\n\nOthers\n\nMildred Perkins, Ethel William\'s lodger\nBernie Leckwith, secretary of the Aldgate branch of the Interpendent Labour Party\nBing Westhampton, Gitz\'s friend \nMarquis of Lowther, "Lowthie," rejected suitor of Maud\n\nAlbert Solman, Fitz\'s man of business \nDr. Greenward, volunteer at the baby clinic\nLord "Johnny" Re\n\n\n\nMany view points, leading up to ww1 and after it. Issue - the length of\nbook. too big. Could if been cut in half - could of been 2 books. \n\nNormally key villan in his book. It isnt key villan. no  cold blooded \nkillers. Multipy political too much political. woman right to vote,\n\nenjoyed characters care about, Billy coal miner from Wales. Innocent young kid,\nend as ww1 vetrium, political,\nWW1. honor the history. why it happened, not biast. everyone view point. \nwell rounded. \n\nResearch 20th centry\n\nKilled so many each other. Our centry. Where we come from.\n1911 welsh mining time. quit school to work.\n\nwhere author comes from. Grandfather went down the pit - like Billy.\n\nsocial divide. money divide. pretend they different. fight, move from \nclasses, fall in love. Class nation divisions. Two familys \n\nSister of Billy, Ethel\nSister of Fitz, Maud\n\nFight for womans rights. Feel deprived. Even upper class was restricted.\nMaud photo captured being arrested by a police officer.\n\n1914, woman 21 not allowed to go anywhere alone. Maud.\n\nRole of Woman. Woman fought political battles. Harsh treated by media \nand police. They won! \n\nmen gave in. woman vote over 30, men over 21. lets be pratible. \npricible. treat equal. split movement.\n\nEvents leading up to ww1. How to tell? Maud fall in love with young \ngerman spy. want to get married. Maud and Walter.\n\nRussian - saving to go to America. Fought in ww1 for russia. men of the \nrevolution.\nOne living american dream. One a revalution in Russia. Grigori and Lev.\n\nGerman invasion of USA. Newspaper. Media quick on haterd on enemys. \nWanted\nto whip up. gone to war no prblem. New weapons. machine guns. made \neverything more terrible. \n'

In [13]:
newest = max(glob.iglob('/home/' + theusr + '/git/writersdenhamilton/posts/*.rst'),
                       key=os.path.getctime)

In [14]:
filename = os.path.basename(newest)

In [15]:
opnew = open(newest, 'r')

In [16]:
newrd = opnew.read()

In [17]:
opnew.close()

In [18]:
nerdrep = newrd.replace('\n', ' ')

In [19]:
nerdsplit = nerdrep.split()

In [20]:
latword = nerdsplit[-1]

In [21]:
wctoday = len(nerdsplit)

In [22]:
print('Writing: ' + filename + ' recent word: ' + latword + '  wc: ' + str(wctoday))


Writing: fallofgiants.rst recent word: terrible.  wc: 450

In [ ]:


In [ ]: