Skip to content

Commit b0e03e6

Browse files
committed
Merge notion branch into pep8
2 parents a8eb7c4 + dcf9e60 commit b0e03e6

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
help="View and organise the playbook",
5656
action='store_true')
5757

58+
parser.add_argument("-no",
59+
"--notion",
60+
help="Login to your Notion account to save playbook",
61+
action='store_true')
62+
5863
ARGV = parser.parse_args()
5964

6065
search_flag = Search(ARGV)

src/arguments/notion.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import os
2+
import json
3+
4+
from .utility import Utility
5+
from .error import SearchError
6+
7+
from selenium import webdriver
8+
from selenium.webdriver.common.by import By
9+
from selenium.webdriver.support.ui import WebDriverWait
10+
from selenium.webdriver.support import expected_conditions as EC
11+
12+
13+
from webdriver_manager.chrome import ChromeDriverManager
14+
from webdriver_manager.firefox import GeckoDriverManager
15+
from webdriver_manager.microsoft import EdgeChromiumDriverManager
16+
17+
def get_token_from_cookie(cookie, token):
18+
for el in cookie:
19+
if el['name'] == token:
20+
return el
21+
pass
22+
23+
class NotionClient():
24+
"""
25+
Handles the entire procedure of connecting to User's Notion account,
26+
generating Notion's tokenv2_cookie, storing it locally and uploading content
27+
to User's space
28+
"""
29+
def __init__(self):
30+
self.tokenv2_cookie = None
31+
self.base_url = "https://www.notion.so/"
32+
self.login_path = "login/"
33+
self.linux_path = "/home/{}/Documents/dynamic".format(os.getenv('USER'))
34+
self.mac_path = "/Users/{}/Documents/dynamic".format(os.getenv('USER'))
35+
self.file_name = 'tokenv2_cookie.key'
36+
37+
def get_token_from_file(self):
38+
raise FileNotFoundError("File not found")
39+
return None
40+
41+
def get_login_path(self):
42+
return self.base_url + self.login_path
43+
44+
def save_token_file(self):
45+
pass
46+
47+
def get_cookies_from_login(self):
48+
"""
49+
Provides the user browser window to login to Notion
50+
Returns the user's cookies which can be used to
51+
access and transfer content to user's Notion account
52+
"""
53+
driver = Utility().get_browser_driver()
54+
try:
55+
driver.get(self.get_login_path())
56+
WebDriverWait(driver, 300).until(
57+
EC.presence_of_element_located((By.CLASS_NAME,
58+
"notion-sidebar-container")))
59+
return driver.get_cookies()
60+
except Exception as e:
61+
print(e)
62+
finally:
63+
driver.quit()
64+
65+
def set_tokenv2_cookie(self):
66+
# Sets 'tokenv2_cookie equal to the particular cookie containing token_v2
67+
if not self.tokenv2_cookie:
68+
try:
69+
self.tokenv2_cookie = self.get_token_from_file()
70+
except:
71+
try:
72+
cookies = self.get_cookies_from_login()
73+
self.tokenv2_cookie = get_token_from_cookie(cookies, 'token_v2')
74+
except Exception as e:
75+
print(e)
76+
77+
def print_token_v2(self):
78+
self.set_tokenv2_cookie()
79+
print(self.tokenv2_cookie)

src/arguments/search.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .save import SaveSearchResults
1111
from .update import UpdateApplication
1212
from .api_test import ApiTesting
13+
from .notion import NotionClient
1314

1415
version = "0.1.0"
1516
class Prompt():
@@ -54,6 +55,8 @@ def search_args(self):
5455
update.check_for_updates()
5556
elif self.arguments.GET:
5657
self.api_test_object.get_request()
58+
elif self.arguments.notion:
59+
NotionClient().print_token_v2()
5760

5861
def search_for_results(self, save=False):
5962
queries = ["What do you want to search", "Tags"]

0 commit comments

Comments
 (0)