from collections import Counter
import xmltodict
import os

#for filera in range(1,28):
    #print (filera)
    
    #use open() for opening file.
    #Always use `with` statement as it'll automatically close the file for you.
    #with open(r'/home/wcmckee/Downloads/writersden/posts/nanowrimo15-day' + str(filera) + '.rst') as f:
        #create a list of all words fetched from the file using a list comprehension
        #words = [word for line in f for word in line.split()]
        #print ("The total word count is:", len(words))
        #now use collections.Counter
        #c = Counter(words)
        #for word, count in c.most_common():
           #print (word, count)

'''
file=open("/home/wcmckee/Downloads/wdm-site/posts/nanowrimo15-day28.rst","r+")
wordcount={}
for word in file.read().split():
    if word not in wordcount:
        wordcount[word] = 1
    else:
        wordcount[word] += 1
for k,v in wordcount.items():
    print(k, v)
    #content = v.decode('utf-8')
'''

dayil = dict()

wcdic = dict()

alwords = dict()

def main():
    #use open() for opening file.
    #Always use `with` statement as it'll automatically close the file for you.
    with open(r'/home/wcmckee/Downloads/writersden/posts/nanowrimo15-day2.rst') as f:
        #create a list of all words fetched from the file using a list comprehension
        words = [word for line in f for word in line.split()]
        print ("The total word count is:", len(words))
        wcdic.update({'wordcount' : len(words)})
        alwords.update({'test':words})
        #now use collections.Counter
        c = Counter(words)
        for word, count in c.most_common():
           print (word, count)
           dayil.update({word : count})
main()

wcdic

"""
Explanation: NaNoWritMoRST
Script to generate RST file daily novel writing
End of explanation
"""


makedailthi = os.listdir('/home/wcmckee/Downloads/writersdenhamilton/posts/')

import arrow

artim = arrow.now()

artim.strftime('%d')

daiyrst = artim.strftime('%d')

yrrst = artim.strftime('%y')

yrrst

fulrst = daiyrst

for maked in makedailthi:
    #print(maked)
    if ('nanowrimo') in makedailthi:
        print(maked)

if ('nanwri' in makedailthi):
    print (makedailthi)

for its in range(1, int(daiyrst) + 1):
    print(its)

"""
Explanation: aspell check
End of explanation
"""


for dakey in dayil.keys():
    if ',' in dakey: 
        print(dakey.replace(',', ''))
    elif '.' in dakey:
        print(dakey.replace('.', ''))

"""
Explanation: Swap this around - number of words as key and word as value
End of explanation
"""


plusonev = list()

isonep = list()

for dayi in dayil.values():
    if dayi > 1:
        print(dayi)
        plusonev.append(dayi)
    elif dayi < 2:
        isonep.append(dayi)

"""
Explanation: How many single words in the file? 
Script to edit. Find and replace certain words/pharses.
Keylog whatever you type
Report generatored at midnight that summery of days writing.
End of explanation
"""


len(isonep)

len(plusonev)

sum(isonep)

sum(plusonev)

sum(isonep) + sum(plusonev)

makedailthi

import requests
import xmltodict

reqartc = requests.get('http://nanowrimo.org/wordcount_api/wchistory/artctrl')

reqtx = reqartc.text

txmls = xmltodict.parse(reqtx)

txkeys = txmls.keys()

txmls['wchistory']['wordcounts']['wcentry'][0]

lentxm = len(txmls['wchistory']['wordcounts']['wcentry'])

wclis = list()

for lent in range(lentxm):
    print(txmls['wchistory']['wordcounts']['wcentry'][lent]['wc'])
    wclis.append(int(txmls['wchistory']['wordcounts']['wcentry'][lent]['wc']))

len(wclis)

sum(wclis)

txmls.values()

"""
Explanation: get the difference between two len
End of explanation
"""


