Code updates
Updated code to use config file
This commit is contained in:
@@ -182,8 +182,22 @@ def export_to_onenote(simplenotes, onenote_mgr, chosen_notebook=None, chosen_sec
|
|||||||
simplenote_id = note.note_id
|
simplenote_id = note.note_id
|
||||||
|
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
filepath = sys.argv[1]
|
||||||
|
|
||||||
|
json_data = json.load(open(filepath))
|
||||||
|
dump = json.dumps(json_data)
|
||||||
|
|
||||||
|
loaded = json.loads(dump)
|
||||||
|
# config = Models.Config(**json.loads((json_data)))
|
||||||
|
config = Models.Config(**loaded)
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
"""
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
print("Provide arguments\n")
|
print("Provide arguments\n")
|
||||||
print("main.py 'username' 'password'")
|
print("main.py 'username' 'password'")
|
||||||
@@ -193,11 +207,24 @@ def main():
|
|||||||
logger.info("simplenote_export running")
|
logger.info("simplenote_export running")
|
||||||
|
|
||||||
cred = Models.SimplenoteCredentials(sys.argv[1], sys.argv[2])
|
cred = Models.SimplenoteCredentials(sys.argv[1], sys.argv[2])
|
||||||
|
|
||||||
print("Username: %s" % (cred.username))
|
print("Username: %s" % (cred.username))
|
||||||
|
"""
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Provide argument")
|
||||||
|
print("Main.py \"config.json\"")
|
||||||
|
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
||||||
print("Hello")
|
print("Hello")
|
||||||
|
|
||||||
|
# notes = get_simplenote_list(cred)
|
||||||
|
|
||||||
|
config = load_config()
|
||||||
|
|
||||||
|
cred_ob = config.vendors['simplenote']
|
||||||
|
cred = Models.SimplenoteCredentials(cred_ob['username'], cred_ob['password'])
|
||||||
notes = get_simplenote_list(cred)
|
notes = get_simplenote_list(cred)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -226,23 +253,32 @@ def main():
|
|||||||
15. Delete the Simplenote note
|
15. Delete the Simplenote note
|
||||||
"""
|
"""
|
||||||
|
|
||||||
onenote_mgr = OneNoteManager.OneNoteManager()
|
# onenote_mgr = OneNoteManager.OneNoteManager(config=config)
|
||||||
|
|
||||||
dev = 1
|
dev = 1
|
||||||
|
|
||||||
token = Models.ResponseToken()
|
token = Models.ResponseToken()
|
||||||
|
|
||||||
if dev == 0:
|
# if dev == 0:
|
||||||
|
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
|
||||||
elif dev == 1:
|
config.token = token.access_token
|
||||||
fi = io.open("token.txt")
|
|
||||||
token.access_token = fi.read()
|
# onenote_mgr = OneNoteManager.OneNoteManager(config=config)
|
||||||
|
# elif dev == 1:
|
||||||
|
elif config.mode == "token":
|
||||||
|
token.access_token = config.token
|
||||||
|
|
||||||
|
# onenote_mgr = OneNoteManager.OneNoteManager(config=config)
|
||||||
else:
|
else:
|
||||||
token = onenote_mgr.fetch_token()
|
token = onenote_mgr.fetch_token()
|
||||||
|
|
||||||
onenote_mgr.load_token(token)
|
config.token = token.access_token
|
||||||
|
|
||||||
|
onenote_mgr = OneNoteManager.OneNoteManager(config=config)
|
||||||
|
# onenote_mgr.load_token(token)
|
||||||
|
|
||||||
export_to_onenote(notes, onenote_mgr, chosen_notebook="Simplenote", chosen_section="From Simplenote")
|
export_to_onenote(notes, onenote_mgr, chosen_notebook="Simplenote", chosen_section="From Simplenote")
|
||||||
|
|
||||||
|
|||||||
@@ -55,3 +55,22 @@ class OneNote(object):
|
|||||||
def __init__(self, title=None, content=None):
|
def __init__(self, title=None, content=None):
|
||||||
self.title = title
|
self.title = title
|
||||||
self.content = content
|
self.content = content
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Config(object):
|
||||||
|
def __init__(self, token=None, secret=None, app_id=None, mode=None, scopes=None, authority_url=None, base_url=None, vendors=None) -> None:
|
||||||
|
# def __init__(self, token=None, secret=None, app_id=None, mode=None, scopes=None, authority_url=None, base_url=None) -> None:
|
||||||
|
self.token = token
|
||||||
|
self.secret = secret
|
||||||
|
self.app_id = app_id
|
||||||
|
self.mode = mode
|
||||||
|
self.scopes = scopes
|
||||||
|
self.authority_url = authority_url
|
||||||
|
self.base_url = base_url
|
||||||
|
self.vendors = vendors
|
||||||
|
|
||||||
|
class Vendor(object):
|
||||||
|
def __init__(self, username=None, password=None) -> None:
|
||||||
|
self.username = username
|
||||||
|
self.password = password
|
||||||
+12
-1
@@ -10,8 +10,19 @@ import Models
|
|||||||
|
|
||||||
class OneNoteManager(object):
|
class OneNoteManager(object):
|
||||||
|
|
||||||
def __init__(self, token=None):
|
def __init__(self, token=None, config=None):
|
||||||
self.token = token
|
self.token = token
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
self.initialize_onenote(self.config)
|
||||||
|
|
||||||
|
def initialize_onenote(self, config):
|
||||||
|
self.__APP_ID = config.app_id
|
||||||
|
self.__SECRET = config.secret
|
||||||
|
self.__SCOPES = config.scopes
|
||||||
|
self.__AUTHORITY_URL = config.authority_url
|
||||||
|
self.__base_url = config.base_url
|
||||||
|
self.__token = Models.ResponseToken(access_token=config.token)
|
||||||
|
|
||||||
|
|
||||||
def __auth_header(self):
|
def __auth_header(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user