I don't understand what's going on here so hopefully one of you can enlighten me.
I subscribe to the RSS feed for http://kupu.maori.nz in MrReader and have a service set up to send a post to a Pythonista script to extract the word of the day and append it to a text file in my Dropbox. But every time it runs, the file shrinks by a number of bytes, usually between 2 and 25. I can't see any correlation between the size of the appended string and the size of the shrinkage.
What am I doing wrong? I'm betting it's something simple I've missed but I dunno.
#coding: utf-8
import sys
import dropboxlogin
from dropbox import rest
import console
import locale
import webbrowser
dropboxlogin.app_key = '...'
dropboxlogin.app_secret = '...'
DB_FOLDER = '/flashcards/'
DB_FILE = 'Māori.cards.txt'
def main():
locale.setlocale(locale.LC_ALL, '')
#extract the word of the day from the RSS text
rss = sys.argv[1]
new_word = rss.split('.')[0]
new_word = new_word.replace(': ', ' :: ')
#this gives us text like "ngeru :: cat"
try:
db = dropboxlogin.get_client()
ff, md = db.get_file_and_metadata(DB_FOLDER + DB_FILE)
wordlist = ff.read().decode('utf-8').splitlines()
ff.close()
print(md) #to check our starting size
wordlist.append(new_word)
wordlist = list(set(wordlist))
wordlist.sort(cmp=locale.strcoll)
md = db.put_file(DB_FOLDER + DB_FILE, u'\n'.join(wordlist), overwrite=True)
print(md) #to see how much we've shrunk
console.hud_alert('added {}'.format(new_word))
except rest.ErrorResponse as e:
console.alert('Error - add_maori.py', message='{}\n'.format(e))
webbrowser.open('mrreader://')
if __name__ == '__main__':
main()