Skip to content
This repository has been archived by the owner on Mar 20, 2019. It is now read-only.

Commit

Permalink
Add initial login and index getting functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrillusions committed Mar 5, 2011
1 parent 113b1df commit 81bedf0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.ini
3 changes: 3 additions & 0 deletions config.ini.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[simplenote]
email: user@example.com
password: CHANGE_ME
64 changes: 59 additions & 5 deletions simplenote.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/usr/bin/env python
# vim:ts=4:sw=4:ft=python:fileencoding=utf-8
"""Getopts template
"""Simplenote CLI
When a script has many command line options, use this.
TODO: perhaps better way to handle global variables, options, etc
Command line interface to simplenote.
"""


import urllib
import urllib2
import base64
import sys
import traceback
from optparse import OptionParser
from ConfigParser import ConfigParser

# Make some effort to be backwards compatible with 2.5
try:
Expand All @@ -30,10 +33,61 @@ def __init__(self, email, password):
self.password = password

def login(self):
pass
# the login url is just api
url = 'https://simple-note.appspot.com/api/login'
data = 'email=' + self.email + '&password=' + self.password
data = base64.b64encode(data)
fh = urllib2.urlopen(url, data)
self.authtok = fh.read()
fh.close()

def note(self):
pass

def delete(self):
pass

def index(self, length=100):
url = self.base_url + 'index'
data = 'length=' + str(length) + '&auth=' + self.authtok + '&email=' + self.email
# this is a get request so everything is sent in url
fh = urllib2.urlopen(url + '?' + data)
index = fh.read()
fh.close()
return(index)


def main():
"""The main function."""
parser = OptionParser(version='%prog v' + __version__)
parser.add_option('-c', '--config', default='config.ini',
help='Location of config file (default: %default)', metavar='FILE')
(options, args) = parser.parse_args()

config = ConfigParser()
config.read(options.config)
email = config.get('simplenote', 'email')
password = config.get('simplenote', 'password')

sn = Simplenote(email, password)
sn.login()
print sn.index(1)


if __name__ == "__main__":
try:
main()
except KeyboardInterrupt, e:
# Ctrl-c
raise e
except SystemExit, e:
# sys.exit()
raise e
except Exception, e:
print "ERROR, UNEXPECTED EXCEPTION"
print str(e)
traceback.print_exc()
sys.exit(1)
else:
# Main function is done, exit cleanly
sys.exit(0)

0 comments on commit 81bedf0

Please sign in to comment.