Completed remaining features
Notes are now added to OneNote and the note is deleted from Simplenote. There is a new issue. Making too many requests in a short period of time
This commit is contained in:
@@ -26,10 +26,11 @@ def contains_title_and_content(content):
|
|||||||
def delete_note(cred, note):
|
def delete_note(cred, note):
|
||||||
sn = simplenote.Simplenote(cred.username, cred.password)
|
sn = simplenote.Simplenote(cred.username, cred.password)
|
||||||
|
|
||||||
print("Hehe!!")
|
# print("Hehe!!")
|
||||||
return
|
# return
|
||||||
|
|
||||||
sn.delete_note(note.note_id)
|
res = sn.delete_note(note.note_id)
|
||||||
|
print("Deleted '%s' from Simplenote" % note.title)
|
||||||
|
|
||||||
|
|
||||||
def get_simplenote_list(cred):
|
def get_simplenote_list(cred):
|
||||||
@@ -56,12 +57,17 @@ def get_simplenote_list(cred):
|
|||||||
# Parse the title from the content
|
# Parse the title from the content
|
||||||
#
|
#
|
||||||
# The title and content are delimited by '\n\n'
|
# The title and content are delimited by '\n\n'
|
||||||
split = title.split("\n\n")
|
split = title.split("\r\n")
|
||||||
|
|
||||||
title = split[0]
|
title = split[0]
|
||||||
|
|
||||||
split.remove(split[0])
|
split.remove(split[0])
|
||||||
content = "\n\n".join(split)
|
|
||||||
|
if len(split) == 1:
|
||||||
|
content = split[0]
|
||||||
|
elif len(split) == 2:
|
||||||
|
content = split[1]
|
||||||
|
|
||||||
|
|
||||||
note = Models.SimpleNote(title, content)
|
note = Models.SimpleNote(title, content)
|
||||||
note.note_id = id
|
note.note_id = id
|
||||||
@@ -83,7 +89,7 @@ def is_valid_notebook(onenote_notebooks, chosen_notebook):
|
|||||||
|
|
||||||
notes = onenote_notebooks
|
notes = onenote_notebooks
|
||||||
|
|
||||||
for value in notes["value"]:
|
for value in notes['value']:
|
||||||
display_name = value["displayName"]
|
display_name = value["displayName"]
|
||||||
|
|
||||||
if display_name == chosen_notebook:
|
if display_name == chosen_notebook:
|
||||||
@@ -145,6 +151,12 @@ def is_valid_note(onenote_notes, onenote_section):
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def note_exists_in_onenote(note, onenote_notes):
|
||||||
|
for o_note in onenote_notes['value']:
|
||||||
|
if note.title == o_note['title']:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def export_to_onenote(simplenotes, onenote_mgr, chosen_notebook=None, chosen_section=None):
|
def export_to_onenote(simplenotes, onenote_mgr, chosen_notebook=None, chosen_section=None):
|
||||||
onenote_notebooks = onenote_mgr.get_notebooks()
|
onenote_notebooks = onenote_mgr.get_notebooks()
|
||||||
@@ -179,7 +191,20 @@ def export_to_onenote(simplenotes, onenote_mgr, chosen_notebook=None, chosen_sec
|
|||||||
return
|
return
|
||||||
|
|
||||||
for note in simplenotes:
|
for note in simplenotes:
|
||||||
simplenote_id = note.note_id
|
if note_exists_in_onenote(note, onenote_notes):
|
||||||
|
continue
|
||||||
|
|
||||||
|
json_data = onenote_mgr.add_note(note, onenote_section)
|
||||||
|
|
||||||
|
if json_data != None or "error" not in json_data:
|
||||||
|
cred = Models.SimplenoteCredentials(username=None, password=None)
|
||||||
|
sn = onenote_mgr.config.vendors['simplenote']
|
||||||
|
|
||||||
|
cred.username = sn['username']
|
||||||
|
cred.password = sn['password']
|
||||||
|
delete_note(cred, note)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
@@ -207,6 +232,16 @@ def main():
|
|||||||
|
|
||||||
config = load_config()
|
config = load_config()
|
||||||
|
|
||||||
|
if config.vendors == None or config.vendors['onenote'] == None:
|
||||||
|
print("No vendor or onenote section")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
o_note = config.vendors['onenote']
|
||||||
|
|
||||||
|
if o_note['target_notebook'] == None or o_note['target_section'] == None:
|
||||||
|
print("Notebook or section is empty")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
cred_ob = config.vendors['simplenote']
|
cred_ob = config.vendors['simplenote']
|
||||||
cred = Models.SimplenoteCredentials(cred_ob['username'], cred_ob['password'])
|
cred = Models.SimplenoteCredentials(cred_ob['username'], cred_ob['password'])
|
||||||
notes = get_simplenote_list(cred)
|
notes = get_simplenote_list(cred)
|
||||||
@@ -228,30 +263,21 @@ def main():
|
|||||||
6. [X] Get OneNote Notes (By section id and check to see if there is a @data.nextLink)
|
6. [X] Get OneNote Notes (By section id and check to see if there is a @data.nextLink)
|
||||||
7. [X] Check to see if the notes are part of the section
|
7. [X] Check to see if the notes are part of the section
|
||||||
8. [X] Get a list of OneNote notes that's part of the section
|
8. [X] Get a list of OneNote notes that's part of the section
|
||||||
9. Iterate through Simplenote notes
|
9. [X] Iterate through Simplenote notes
|
||||||
10. Check to see if a OneNote note exists that comes from the selected notebook and section. Terminate if not
|
10. [X] Check to see if a OneNote note exists that comes from the selected notebook and section. Terminate if not
|
||||||
11. Check to see if the iterated Simplenote note exists in OneNote with the matched criteria. Terminate if so
|
11. [X] Create page in OneNote using the iterated Simplenote note
|
||||||
12. Create page in OneNote using the iterated Simplenote note
|
12. [X] Retrieve the OneNote pages again
|
||||||
13. Retrieve the OneNote pages again
|
13. [X] Check to see if the page has been created
|
||||||
14. Check to see if the page has been created
|
14. [X] Delete the Simplenote note
|
||||||
15. Delete the Simplenote note
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# onenote_mgr = OneNoteManager.OneNoteManager(config=config)
|
|
||||||
|
|
||||||
dev = 1
|
|
||||||
|
|
||||||
token = Models.ResponseToken()
|
token = Models.ResponseToken()
|
||||||
|
|
||||||
# if dev == 0:
|
|
||||||
if config.mode == "token input":
|
if config.mode == "token input":
|
||||||
print("Enter token: ")
|
print("Enter token: ")
|
||||||
token_input = input()
|
token_input = input()
|
||||||
token.access_token = token_input
|
token.access_token = token_input
|
||||||
config.token = token.access_token
|
config.token = token.access_token
|
||||||
|
|
||||||
# onenote_mgr = OneNoteManager.OneNoteManager(config=config)
|
|
||||||
# elif dev == 1:
|
|
||||||
elif config.mode == "token":
|
elif config.mode == "token":
|
||||||
token.access_token = config.token
|
token.access_token = config.token
|
||||||
else:
|
else:
|
||||||
@@ -261,12 +287,11 @@ def main():
|
|||||||
|
|
||||||
onenote_mgr = OneNoteManager.OneNoteManager(config=config)
|
onenote_mgr = OneNoteManager.OneNoteManager(config=config)
|
||||||
|
|
||||||
export_to_onenote(notes, onenote_mgr, chosen_notebook="Simplenote", chosen_section="From Simplenote")
|
chosen_notebook = config.vendors['onenote']['target_notebook']
|
||||||
|
chosen_section = config.vendors['onenote']['target_section']
|
||||||
|
export_to_onenote(notes, onenote_mgr, chosen_notebook=chosen_notebook, chosen_section=chosen_section)
|
||||||
|
|
||||||
|
|
||||||
# iterate_simplenotes(notes)
|
|
||||||
|
|
||||||
|
|
||||||
logger = log21.get_logger('My Logger', level_names={21: 'SpecialInfo', log21.WARNING: ' ! ', log21.ERROR: '!!!'})
|
logger = log21.get_logger('My Logger', level_names={21: 'SpecialInfo', log21.WARNING: ' ! ', log21.ERROR: '!!!'})
|
||||||
logger.log(21, 'Here', '%s', 'GO!', args=('we',))
|
logger.log(21, 'Here', '%s', 'GO!', args=('we',))
|
||||||
|
|
||||||
|
|||||||
+10
-7
@@ -83,19 +83,22 @@ class OneNoteManager(object):
|
|||||||
return notes
|
return notes
|
||||||
|
|
||||||
# Implement this function
|
# Implement this function
|
||||||
def add_note(self, note):
|
def add_note(self, note, onenote_section):
|
||||||
|
section_id = onenote_section['id']
|
||||||
|
|
||||||
url = "https://graph.microsoft.com/v1.0/me/onenote/sections/{section-id}/pages"
|
url = f"https://graph.microsoft.com/v1.0/me/onenote/sections/{section_id}/pages"
|
||||||
|
|
||||||
data = {"dsfsdf", "sdfsdf"}
|
data = self.note_to_data(note)
|
||||||
headers = self.__auth_header()
|
headers = self.__auth_header()
|
||||||
|
headers['Content-type'] = "application/xhtml+xml"
|
||||||
req = requests.post(url, data=data, headers=headers)
|
req = requests.post(url, data=data, headers=headers)
|
||||||
content = req.content
|
content = req.content
|
||||||
j_obj = content.decode("utf8").replace("'", '"')
|
j_obj = content.decode("utf8")
|
||||||
|
|
||||||
json_data = json.dumps(j_obj)
|
json_data = json.dumps(j_obj)
|
||||||
|
|
||||||
print("Add")
|
if "error" not in json_data:
|
||||||
|
print("Added note '%s' to OneNote" % note.title)
|
||||||
|
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
@@ -107,9 +110,9 @@ class OneNoteManager(object):
|
|||||||
data =""
|
data =""
|
||||||
|
|
||||||
if content_str == "":
|
if content_str == "":
|
||||||
data = f"<!DOCTYPE html><html><head><title>title_str</title></head> <body></body></html>"
|
data = f"<!DOCTYPE html><html><head><title>{title_str}</title></head> <body></body></html>"
|
||||||
else:
|
else:
|
||||||
data = f"<!DOCTYPE html><html><head><title>title_str</title></head> <body>content_str</body></html>"
|
data = f"<!DOCTYPE html><html><head><title>{title_str}</title></head> <body>{content_str}</body></html>"
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user