├── .gitignore ├── README.md ├── download.py ├── requirements.txt ├── run.sh └── settings.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | .last_update 2 | notes/ 3 | env/ 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simplenote-to-git Backup 2 | 3 | ![Simplenote-to-git](http://i.imgur.com/H14JXV2.png) 4 | 5 | This is a small package that enables you to back up your Simplenote notes to a git repo! This is compatible with both standard git repos and github gists. 6 | 7 | ### Requirements 8 | 9 | - Python 2.7+ 10 | - Virtualenv 11 | - git 12 | 13 | ### Execution 14 | 15 | - Fill in settings.cfg 16 | - Run `./run.sh` 17 | 18 | If you are going to use this script, I would recommend setting it up to run hourly with cron: 19 | 20 | 0 * * * * bash /path/to/run.sh 21 | -------------------------------------------------------------------------------- /download.py: -------------------------------------------------------------------------------- 1 | from simplenote import Simplenote 2 | from decimal import Decimal 3 | import sys 4 | 5 | username = sys.argv[1] 6 | password = sys.argv[2] 7 | 8 | 9 | simplenote = Simplenote(username, password) 10 | 11 | noteresponse = simplenote.get_note_list() 12 | last_update_file = open('notes/.last_update', 'r') 13 | try: 14 | last_update = Decimal(last_update_file.read()) 15 | except Exception as e: 16 | last_update = Decimal('0') 17 | last_update_file.close() 18 | most_recently_updated = '0' 19 | 20 | notes = noteresponse[0] 21 | print("Checking %d notes..." % len(notes)) 22 | for note in notes: 23 | if (Decimal(note['modifydate']) > last_update): 24 | print(' Reading contents of %s' % note['key']) 25 | note_data = simplenote.get_note(note['key']) 26 | print(' Writing contents of %s' % note['key']) 27 | filename = 'notes/%s' % note['key'] 28 | f = open(filename, 'w') 29 | f.write(note_data[0]['content']) 30 | f.close() 31 | else: 32 | print('Skipped %s, no changes.' % note['key']) 33 | if (Decimal(note['modifydate']) > Decimal(most_recently_updated)): 34 | most_recently_updated = note['modifydate'] 35 | 36 | last_update_file = open('notes/.last_update', 'w') 37 | last_update_file.write(str(most_recently_updated)) 38 | last_update_file.close() 39 | 40 | print('Download of notes complete.') 41 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | simplenote==2.1.4 2 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Simplenote-to-git 3 | # This backup solution is designed to allow you to back up your 4 | # Simplenote notes to a git repo. This is completely compatible 5 | # github's gist service. 6 | # 7 | # By default, this script does not delete notes. 8 | # 9 | # To start using this script, fill in settings.cfg with your 10 | # Simplenote credentials and the URL of the repo you would like 11 | # to back up to. 12 | 13 | if [ ! "${0%/*}" = "${0}" ] ; then 14 | cd ${0%/*} 15 | fi 16 | 17 | source settings.cfg 18 | if [ "$simplenote_username" = "" ] ; then 19 | echo "Your username is not set for SimpleNote in settings.cfg!" 20 | exit 1 21 | fi 22 | if [ "$simplenote_password" = "" ] ; then 23 | echo "Your password is not set for SimpleNote in settings.cfg!" 24 | exit 2 25 | fi 26 | if [ "$git_repo" = "" ] ; then 27 | echo "Please point to a git repo in settings.cfg." 28 | exit 3 29 | fi 30 | if [ "$git_branch" = "" ] ; then 31 | echo "Please configure which branch you would like to pull from." 32 | exit 4 33 | fi 34 | 35 | 36 | echo "Checking if the notes folder exists" 37 | if [ ! -d notes ] ; then 38 | mkdir notes 39 | fi 40 | 41 | echo "Checking if there is currently a repo in the notes directory" 42 | if [ -d notes/.git ]; then 43 | # This repo currently exists. 44 | cd notes 45 | git pull origin $git_branch --no-rebase 46 | cd .. 47 | else 48 | # We need to check out this repo 49 | cd notes 50 | git init 51 | git remote add origin $git_repo 52 | git pull origin $git_branch --no-rebase 53 | cd .. 54 | fi 55 | 56 | echo "Updating the .gitignore" 57 | touch .gitignore 58 | cat .gitignore > notes/.gitignore 59 | touch notes/.last_update 60 | 61 | echo "Running the downloader script:" 62 | if [ ! -d env ] ; then 63 | python3 -m venv env 64 | fi 65 | source env/bin/activate 66 | pip install --upgrade pip 67 | pip install -r requirements.txt 68 | python download.py "$simplenote_username" "$simplenote_password" 69 | 70 | echo "Commit the changes to the remote repo" 71 | cd notes 72 | git add . 73 | git commit -am "Changes update on $(date +%Y-%m-%d) at $(date +%H:%M)" 74 | git push origin $git_branch 75 | 76 | echo "Backup completed" 77 | -------------------------------------------------------------------------------- /settings.cfg: -------------------------------------------------------------------------------- 1 | simplenote_username= 2 | simplenote_password= 3 | git_repo= 4 | git_branch=master 5 | 6 | --------------------------------------------------------------------------------