Ejemplo n.º 1
0
 def test_simplenote_add_note_content(self):
     res, status = Simplenote(self.user, self.password).add_note("new note")
     if status == 0:
         note, status = Simplenote(self.user,
                                   self.password).get_note(res["key"])
         if status == 0:
             self.assertEqual("new note", note["content"])
Ejemplo n.º 2
0
 def clear_all_notes(self):
     res, status = Simplenote(self.user, self.password).get_note_list()
     if status == 0:
         [
             Simplenote(self.user, self.password).delete_note(n["key"])
             for n in res
         ]
Ejemplo n.º 3
0
 def test_note_with_plus_signs(self):
     note, status = Simplenote(self.user, self.password).add_note("++")
     if status == 0:
         note, status = Simplenote(self.user,
                                   self.password).get_note(note["key"])
         if status == 0:
             self.assertEqual("++", note["content"])
Ejemplo n.º 4
0
 def test_simplenote_update_note(self):
     note = {}
     note['key'] = self.first_note
     note["content"] = "Updated Note."
     note, status = Simplenote(self.user, self.password).update_note(note)
     if status == 0:
         note, status = Simplenote(self.user,
                                   self.password).get_note(note["key"])
         if status == 0:
             self.assertEqual("Updated Note.",
                              note["content"].split('\n')[0])
Ejemplo n.º 5
0
    def test_simplenote_trash_note(self):
        if self.first_note != False:
            note, status = Simplenote(self.user, self.password).trash_note(
                self.first_note)
            if status == 0:
                self.assertEqual(1, note["deleted"])

        if self.second_note != False:
            note, status = Simplenote(self.user, self.password).trash_note(
                self.second_note)
            if status == 0:
                self.assertEqual(1, note["deleted"])
Ejemplo n.º 6
0
    def test_simplenote_get_list_length_longer_than_note_fetch_length(self):
        while self.initial_note_count <= simplenote.simplenote.NOTE_FETCH_LENGTH + 1:
            note, status = Simplenote(
                self.user,
                self.password).add_note("Note " +
                                        str(self.initial_note_count + 1))
            if status == 0:
                self.initial_note_count += 1

        res, status = Simplenote(self.user, self.password).get_note_list()
        if status == 0:
            self.assertTrue(len(res) > simplenote.simplenote.NOTE_FETCH_LENGTH)
Ejemplo n.º 7
0
def save_notes():
    user = ''
    pw = ''
    note = []
    simple = Simplenote(user, pw)

    #Get auth
    token = simple.authenticate(user, pw)

    #Get list of notes
    print "Retrieving list"
    l = simple.get_note_list()
    length = len(l[0])
    print length
    count = 0
    print "Processing list.."
    while count < length:
        print count
        note += simple.get_note(l[0][count]['key'])
        count += 1
    filename = t + '.txt'
    file = open(filename, 'w')
    #To track progress
    for item in note:
        print >> file, item
    file.close()
    #Dump note object to pickle for use by other programs
    import pickle
    pickle.dump(note, open(t + '.pickle', 'wb'))
Ejemplo n.º 8
0
 def test_simplenote_first_note(self):
     if self.first_note != False:
         note, status = Simplenote(self.user,
                                   self.password).get_note(self.first_note)
         if status == 0:
             self.assertTrue(type(note) == dict)
             self.assertEqual("First Note.", note["content"].split('\n')[0])
Ejemplo n.º 9
0
    def test_simplenote_delete_note(self):
        if self.first_note != False:
            note, status = Simplenote(self.user, self.password).delete_note(
                self.first_note)
            if status == 0:
                note, status = Simplenote(self.user, self.password).get_note(
                    self.first_note)
                self.assertEqual(-1, status)

        if self.second_note != False:
            note, status = Simplenote(self.user, self.password).delete_note(
                self.second_note)
            if status == 0:
                note, status = Simplenote(self.user, self.password).get_note(
                    self.second_note)
                self.assertEqual(-1, status)
Ejemplo n.º 10
0
    def __init__(self, config):
        utils.SubjectMixin.__init__(self)

        self.config = config

        # create db dir if it does not exist
        if not os.path.exists(config.db_path):
            os.mkdir(config.db_path)

        self.db_path = config.db_path

        now = time.time()
        # now read all .json files from disk
        fnlist = glob.glob(self.helper_key_to_fname('*'))
        self.notes = {}
        for fn in fnlist:
            n = json.load(open(fn, 'rb'))
            # we always have a localkey, also when we don't have a note['key'] yet (no sync)
            localkey = os.path.splitext(os.path.basename(fn))[0]
            self.notes[localkey] = n
            # we maintain in memory a timestamp of the last save
            # these notes have just been read, so at this moment
            # they're in sync with the disc.
            n['savedate'] = now

        # initialise the simplenote instance we're going to use
        # this does not yet need network access
        self.simplenote = Simplenote(config.sn_username, config.sn_password)

        # we'll use this to store which notes are currently being synced by
        # the background thread, so we don't add them anew if they're still
        # in progress. This variable is only used by the background thread.
        self.threaded_syncing_keys = {}

        # reading a variable or setting this variable is atomic
        # so sync thread will write to it, main thread will only
        # check it sometimes.
        self.waiting_for_simplenote = False

        # save and sync queue
        self.q_save = Queue()
        self.q_save_res = Queue()

        thread_save = Thread(target=self.worker_save)
        thread_save.setDaemon(True)
        thread_save.start()

        self.q_sync = Queue()
        self.q_sync_res = Queue()

        thread_sync = Thread(target=self.worker_sync)
        thread_sync.setDaemon(True)
        thread_sync.start()
Ejemplo n.º 11
0
 def setUp(self):
     self.user = "******"
     self.password = "******"
     self.clear_all_notes()
     self.unicode_note = "∮ E⋅da = Q,  n → ∞, ∑ f(i) = ∏ g(i),      ⎧⎡⎛┌─────┐⎞⎤⎫"
     self.unicode_note_key = False
     self.initial_note_count = 0
     self.first_note = False
     self.second_note = False
     note, status = Simplenote(self.user,
                               self.password).add_note("First Note.")
     if status == 0:
         self.initial_note_count += 1
         self.first_note = note['key']
     note, status = Simplenote(self.user,
                               self.password).add_note("Second Note.")
     if status == 0:
         self.initial_note_count += 1
         self.second_note = note['key']
     note, status = Simplenote(self.user,
                               self.password).add_note(self.unicode_note)
     if status == 0:
         self.initial_note_count += 1
         self.unicode_note_key = note['key']
Ejemplo n.º 12
0
def main():
    argvs = sys.argv
    argc = len(argvs)

    if not argc == 2:
        print 'Usage: # python %s filename' % argvs[0]
        quit()

    notes = parseNoteXML(argvs[1])

    print "simplenote address:"
    address = raw_input()
    print "simplenote password:"******"Wrong simplenote address or password."
            quit()
Ejemplo n.º 13
0
 def test_simplenote_get_list_length(self):
     res, status = Simplenote(self.user, self.password).get_note_list()
     if status == 0:
         self.assertEqual(self.initial_note_count, len(res))
     else:
         self.assertEqual(0, len(res))
Ejemplo n.º 14
0
def grades_note_update(note_id):
    simplenote = Simplenote(EMAIL,PASSWORD)
    grades = simplenote.get_note(note_id)[0]
    grades['content'] = NOTE_NAME + "\n" + get_grades() + "Last updated: " + str(datetime.now())
    simplenote.update_note(grades)
Ejemplo n.º 15
0
def grades_note_setup():
    simplenote = Simplenote(EMAIL,PASSWORD)
    return simplenote.add_note(NOTE_NAME)[0]['key']
Ejemplo n.º 16
0
class NotesDB(utils.SubjectMixin):
    """NotesDB will take care of the local notes database and syncing with SN.
    """
    def __init__(self, config):
        utils.SubjectMixin.__init__(self)

        self.config = config

        # create db dir if it does not exist
        if not os.path.exists(config.db_path):
            os.mkdir(config.db_path)

        self.db_path = config.db_path

        # create txt Notes dir if it does not exist
        if self.config.notes_as_txt and not os.path.exists(config.txt_path):
            os.mkdir(config.txt_path)

        now = time.time()
        # now read all .json files from disk
        fnlist = glob.glob(self.helper_key_to_fname('*'))
        txtlist = glob.glob(self.config.txt_path + '/*.txt')
        txtlist += glob.glob(self.config.txt_path + '/*.mkdn')

        # removing json files and force full full sync if using text files
        # and none exists and json files are there
        if self.config.notes_as_txt and not txtlist and fnlist:
            logging.debug('Forcing resync: using text notes, first usage')
            for fn in fnlist:
                os.unlink(fn)
            fnlist = []

        self.notes = {}
        if self.config.notes_as_txt:
            self.titlelist = {}

        for fn in fnlist:
            try:
                n = json.load(open(fn, 'rb'))
                if self.config.notes_as_txt:
                    nt = utils.get_note_title_file(n)
                    tfn = os.path.join(self.config.txt_path, nt)
                    if os.path.isfile(tfn):
                        self.titlelist[n.get('key')] = nt
                        txtlist.remove(tfn)
                        if os.path.getmtime(tfn) > os.path.getmtime(fn):
                            logging.debug('Text note was changed: %s' % (fn, ))
                            #with open(tfn, mode='r') as f:
                            with codecs.open(tfn, mode='rb',
                                             encoding='utf-8') as f:
                                c = f.read()

                            n['content'] = c
                            n['modifydate'] = os.path.getmtime(tfn)
                    else:
                        logging.debug('Deleting note : %s' % (fn, ))
                        if not self.config.simplenote_sync:
                            os.unlink(fn)
                            continue
                        else:
                            n['deleted'] = 1
                            n['modifydate'] = now

            except ValueError, e:
                logging.error('Error parsing %s: %s' % (fn, str(e)))

            else:
                # we always have a localkey, also when we don't have a note['key'] yet (no sync)
                localkey = os.path.splitext(os.path.basename(fn))[0]
                self.notes[localkey] = n
                # we maintain in memory a timestamp of the last save
                # these notes have just been read, so at this moment
                # they're in sync with the disc.
                n['savedate'] = now

        if self.config.notes_as_txt:
            for fn in txtlist:
                logging.debug('New text note found : %s' % (fn), )
                tfn = os.path.join(self.config.txt_path, fn)
                #with open(tfn, mode='r') as f:
                with codecs.open(tfn, mode='rb', encoding='utf-8') as f:
                    c = f.read()

                nk = self.create_note(c)
                nn = os.path.splitext(os.path.basename(fn))[0]
                if nn != utils.get_note_title(self.notes[nk]):
                    self.notes[nk]['content'] = nn + "\n\n" + c

                os.unlink(tfn)

        # save and sync queue
        self.q_save = Queue()
        self.q_save_res = Queue()

        thread_save = Thread(target=self.worker_save)
        thread_save.setDaemon(True)
        thread_save.start()

        # initialise the simplenote instance we're going to use
        # this does not yet need network access
        if self.config.simplenote_sync:
            self.simplenote = Simplenote(config.sn_username,
                                         config.sn_password)

            # we'll use this to store which notes are currently being synced by
            # the background thread, so we don't add them anew if they're still
            # in progress. This variable is only used by the background thread.
            self.threaded_syncing_keys = {}

            # reading a variable or setting this variable is atomic
            # so sync thread will write to it, main thread will only
            # check it sometimes.
            self.waiting_for_simplenote = False

            self.q_sync = Queue()
            self.q_sync_res = Queue()

            thread_sync = Thread(target=self.worker_sync)
            thread_sync.setDaemon(True)
            thread_sync.start()
Ejemplo n.º 17
0
 def __init__(self, username, password, num=10000):
     self._note_list = []
     self._handle = Simplenote(username, password)
     self._note_list, _ = self._handle.get_note_list(num)
     self._get_note_content()
Ejemplo n.º 18
0
#A simple Python utility to upload grade information to simple note in real time
#Author: Eden Zik

from simplenote import Simplenote
from datetime import datetime
from sage import get_grades

EMAIL = '???@???.com'  #Simplenote email
PASSWORD = '******'  #Simplenote password

simplenote = Simplenote(EMAIL, PASSWORD)

GRADES_NOTE_ID = 'bf634100f62811e4a205db0538ecac0d'  #Note ID of Grades Note

grades = simplenote.get_note(GRADES_NOTE_ID)[0]

grades['content'] = "Grades\n" + get_grades() + "Last updated: " + str(
    datetime.now())

simplenote.update_note(grades)
Ejemplo n.º 19
0
def add_note(note):
        simple = Simplenote(USER, PW)

        #Get auth
        token = simple.authenticate(USER, PW)
	t = simple.add_note(note)
Ejemplo n.º 20
0
def main():
    parser = OptionParser()
    parser.add_option("--snort",
                      action="store",
                      type="string",
                      help="Import a new file SNORT to Simplenote")
    parser.add_option(
        "--sniff",
        action="store",
        nargs=2,
        type="string",
        help="Link a file with an already existing note in  Simplenote",
        metavar="<key> <filename>")
    parser.add_option("--sneeze",
                      action="store",
                      nargs=2,
                      type="string",
                      help="Export an existing file from Simplenote",
                      metavar="<key> <filename>")
    parser.add_option("--blow",
                      action="store",
                      type="string",
                      help="Roll back note of key BLOW to previous version")
    parser.add_option("--sync",
                      help="Sync files in index",
                      default=False,
                      action='store_true')
    parser.add_option("--hanky",
                      help="Use with --sync to perform a dry run",
                      default=False,
                      action='store_true')
    parser.add_option("--snot",
                      help="List notes available for export (tagged snose)",
                      default=False,
                      action='store_true')
    parser.add_option("--username",
                      action="store",
                      type="string",
                      help="Your Simplenote email address")
    parser.add_option("--password",
                      action="store",
                      type="string",
                      help="Your Simplenote password")
    (options, args) = parser.parse_args()

    if not options.username or not options.password:
        #Check to see if stored somewhere
        try:
            options.username = netrc.netrc().authenticators(
                "simple-note.appspot.com")[0]
            options.password = netrc.netrc().authenticators(
                "simple-note.appspot.com")[2]
        except IOError as e:
            print 'Username and password must be supplied or exist .netrc file under domain of simple-note.appspot.com'
            exit()
    snclient = Simplenote(options.username, options.password)
    if options.snort:
        snort(snclient, options.snort)
    elif options.sniff:
        sniff(snclient, options.sniff[0], options.sniff[1])
    elif options.sneeze:
        sneeze(snclient, options.sneeze[0], options.sneeze[1])
    elif options.blow:
        blow(snclient, options.blow)
    elif options.snot:
        snot(snclient)
    elif options.sync and options.hanky:
        sync(snclient, True)
    elif options.sync:
        sync(snclient)
    else:
        print 'No options supplied'
Ejemplo n.º 21
0
 def test_simplenote_failed_auth(self):
     s = Simplenote(self.user, "")
     self.assertRaises(SimplenoteLoginFailed, s.get_token)
Ejemplo n.º 22
0
 def test_simplenote_auth(self):
     token = Simplenote(self.user, self.password).get_token()
     self.assertNotEqual(None, token)
Ejemplo n.º 23
0
 def test_simplenote_is_unicode(self):
     if self.unicode_note_key != False:
         note, status = Simplenote(self.user, self.password).get_note(
             self.unicode_note_key)
         if status == 0:
             self.assertTrue(self.is_utf8(note["content"]))
Ejemplo n.º 24
0
    pickleread()
    last_synch_finish = d
    picklewrite()


def last_synch_read():  # this is start of some future code
    (last_synch_finish, notes, name_keys) = pickleread()
    # local_changed = list of files mod since last_synch_finish # filename and moddate
    # cloud_changed = list of notes mod since last_synch_finish # initially just key and moddate
    for f in local_changed:
        if f not in name_keys.keys():
            push_new(f)


from simplenote import Simplenote  # http://pypi.python.org/pypi/simplenote/0.2.0
simplenote = Simplenote(username, password)


def cloud_list_create():
    (notes, status) = simplenote.get_note_list()  # have to get the whole list


if __name__ == '__main__':
    cloud_raw_list_grab()
    # map_create()
    # moddate_compare()
    # last_synch_hack()
    map_show()
    # push_local_to_cloud()
    # dedupe_and_map_create(True)
    # map_dupe_check()
Ejemplo n.º 25
0
def grades_note_setup:
    simplenote = Simplenote(EMAIL,PASSWORD)
    simplenote.add_note("Grades")