<commit_before>import os, sys, json
from simperium.core import Api as SimperiumApi

appname = 'chalk-bump-f49' # Simplenote
token = os.environ['TOKEN']
backup_dir = sys.argv[1] if len(sys.argv) > 1 else (os.path.join(os.environ['HOME'], "Dropbox/SimplenoteBackups"))
print "Starting backup your simplenote to: %s" % backup_dir
if not os.path.exists(backup_dir):
    print "Creating directory: %s" % backup_dir
    os.makedirs(backup_dir)

api = SimperiumApi(appname, token)
#print token
notes = api.note.index(data=True)
for note in notes['index']:
    path = os.path.join(backup_dir, note['id'] + '.txt')
    #print path
    with open(path, "w") as f:
        # print json.dumps(note, indent=2)
        #f.write("id: %s\n" % note['id'])
        f.write(note['d']['content'].encode('utf8'))
        f.write("\n")
        f.write("Tags: %s\n" % ", ".join(note['d']['tags']).encode('utf8'))

print "Done: %d files." % len(notes['index'])
<commit_msg>Set the modification dates of the created files to that of the notes<commit_after>import os, sys, json
from simperium.core import Api as SimperiumApi

appname = 'chalk-bump-f49' # Simplenote
token = os.environ['TOKEN']
backup_dir = sys.argv[1] if len(sys.argv) > 1 else (os.path.join(os.environ['HOME'], "Dropbox/SimplenoteBackups"))
print "Starting backup your simplenote to: %s" % backup_dir
if not os.path.exists(backup_dir):
    print "Creating directory: %s" % backup_dir
    os.makedirs(backup_dir)

api = SimperiumApi(appname, token)
#print token
notes = api.note.index(data=True)
for note in notes['index']:
    path = os.path.join(backup_dir, note['id'] + '.txt')
    #print path
    with open(path, "w") as f:
        # print json.dumps(note, indent=2)
        #f.write("id: %s\n" % note['id'])
        f.write(note['d']['content'].encode('utf8'))
        f.write("\n")
        f.write("Tags: %s\n" % ", ".join(note['d']['tags']).encode('utf8'))
    os.utime(path,(note['d']['modificationDate'],note['d']['modificationDate']))

print "Done: %d files." % len(notes['index'])

{'fraction_non_alphanumeric': 0.18651574803149606, 'fraction_numerical': 0.006889763779527559, 'mean_word_length': 4.173027989821883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2056964', 'n_tokens_mistral': 738, 'n_tokens_neox': 737, 'n_words': 169}