import json import webbrowser import subprocess import ast import msal import requests import Models """ APP_ID = "3079e919-8f04-41b7-8b97-5694679bd4f3" SECRET = "23379d03-b2a5-4dd2-a4d0-233b3b40588f" SECRET = "v-Z8Q~iy~vA77IarV5izSqG0e3uX-qBtItFHudd2" # "Notes.Create", "Notes.Read", "Notes.Read.All", "Notes.ReadWrite", "Notes.ReadWrite.All", "Notes.ReadWrite.CreatedByApp" # SCOPES = [''] SCOPES = ["Notes.Create", "Notes.Read", "Notes.Read.All", "Notes.ReadWrite", "Notes.ReadWrite.All", "Notes.ReadWrite.CreatedByApp"] AUTHORITY_URL = "https://login.microsoftonline.com/consumers/" base_url = "https://graph.microsoft.com/v1.0/" endpoint = base_url + "me" """ class OneNoteManager(object): def __init__(self, token=None): self.token = token def __auth_header(self): headers = {"Authorization": f"Bearer {self.__token.access_token}"} return headers # retrieving OneNote notebooks def get_notebooks(self): url = "https://graph.microsoft.com/v1.0/me/onenote/notebooks" headers = self.__auth_header() req = requests.get(url, headers=headers) content = req.content j_obj = content.decode("utf8") note_d = dict() note_d = json.loads(j_obj) return note_d return json_data # retrieving OneNote sections def get_sections(self): url = "https://graph.microsoft.com/v1.0/me/onenote/sections" headers = self.__auth_header() req = requests.get(url, headers=headers) content = req.content j_obj = content.decode("utf8") sect_d = dict() sect_d = json.loads(j_obj) return sect_d # retrieving OneNote notes given a url def get_notes(self, url): notes = dict() headers = self.__auth_header() req = requests.get(url, headers=headers) content = req.content j_obj = content.decode("utf8") notes = json.loads(j_obj) if "@odata.nextLink" in notes: nextLink = notes["@odata.nextLink"] notes_s = self.get_notes(nextLink) for note in notes_s["value"]: notes["value"].append(note) return notes # Implement this function def add_note(self, note): url = "https://graph.microsoft.com/v1.0/me/onenote/sections/{section-id}/pages" data = {"dsfsdf", "sdfsdf"} headers = self.__auth_header() req = requests.post(url, data=data, headers=headers) content = req.content j_obj = content.decode("utf8").replace("'", '"') json_data = json.dumps(j_obj) print("Add") return json_data # Returns string representation of the note used for creating pages def note_to_data(self, note): title_str = note.title content_str = note.content data ="" if content_str == "": data = f"