Skip to content

Instantly share code, notes, and snippets.

@ciiqr
ciiqr / activate_app_if_running.py
Last active August 29, 2015 14:03 — forked from noamraph/activate_app_if_running.py
Run or Raise using DBus
"""
Allow an application to activate a running instance of itself instead of
starting another instance.
"""
## Usage ##
# import sys
# APP_ID = "com.example.application"
# if activate_if_already_running(APP_ID):
# sys.exit(0)
#
import sys
import re
from enauath import client
from string import Template
#Accepts the GUID(string) of the note you want to append
def appendNote(guid):
#Get the note to be updated using the note's guid http://dev.evernote.com/documentation/reference/NoteStore.html#Fn_NoteStore_getNote
noteStore = client.get_note_store()
note = Types.Note()
note.title = "I'm a test note!"
note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
note.content += '<en-note>Hello, world!</en-note>'
note = noteStore.createNote(note)
noteStore = client.get_note_store()
notebook = Types.Notebook()
notebook.name = "My Notebook"
notebook = noteStore.createNotebook(notebook)
print notebook.guid
def makeNote(authToken, noteStore, noteTitle, noteBody, parentNotebook=None):
nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
nBody += "<en-note>%s</en-note>" % noteBody
## Create note object
ourNote = Types.Note()
ourNote.title = noteTitle
ourNote.content = nBody
def makeResourceFromFiles(fpaths):
"""
Create a Resource object from the passed file(s) and return it
"""
for fpath in fpaths:
if not os.path.exists(fpath):
print "Path doesn't exist: %s" % fpath
continue
# try to determine the MIME type of the file
def makeNote(authToken, noteStore, noteTitle, noteBody, resources=[], parentNotebook=None):
"""
Create a Note instance with title and body
Send Note object to user's account
"""
ourNote = Types.Note()
ourNote.title = noteTitle
## Build body of note
def getUserShardId(authToken, userStore):
"""
Get the User from userStore and return the user's shard ID
"""
try:
user = userStore.getUser(authToken)
except (Errors.EDAMUserException, Errors.EDAMSystemException), e:
print "Exception while getting user's shardID:"
print type(e), e
return None
def shareSingleNote(authToken, noteStore, userStore, noteGuid, shardId=None):
"""
Share a single note and return the public URL for the note
"""
if not shardId:
shardId = getUserShardId(authToken, userStore)
if not shardId:
raise SystemExit
try:
def stopSharingSingleNote(authToken, noteStore, noteGuid):
try:
noteStore.stopSharingNote(authToken, noteGuid)
except (EDAMNotFoundException, EDAMSystemException, EDAMUserException), e:
print "Error stopping sharing note:"
print type(e), e
return None
return noteGuid