Skip to content

Commit 111b854

Browse files
committed
Fix codacy issues
1 parent 9ff3253 commit 111b854

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

src/arguments/notion.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
2-
import sys
32

4-
from .utility import Utility
5-
from .error import SearchError
3+
from .utility import get_browser_driver
64
from .settings import LOGIN_PATH
75
from .settings import TOKEN_FILE_PATH
86

@@ -17,11 +15,18 @@ def get_token_from_cookie(cookie, token):
1715

1816
class NotionClient():
1917
"""
18+
Implements Login and token retrieval
19+
2020
Handles the entire procedure of connecting to User's Notion account,
21-
generating Notion's tokenv2_cookie, storing it locally and uploading content
22-
to User's space
21+
generating Notion's tokenv2_cookie, storing it locally and uploading
22+
content to User's space
2323
"""
2424
def __init__(self):
25+
"""
26+
No input parameters required for instatiating object.
27+
tokenv2_cookie stores the cookie containing user's tokenv2
28+
tokenv2_key is used to create environment variable
29+
"""
2530
self.tokenv2_cookie = None
2631
self.tokenv2_key = 'TOKENV2'
2732

@@ -47,7 +52,7 @@ def get_cookies_from_login(self):
4752
Returns the user's cookies which can be used to
4853
access and transfer content to user's Notion account
4954
"""
50-
driver = Utility().get_browser_driver()
55+
driver = get_browser_driver()
5156
try:
5257
driver.get(LOGIN_PATH)
5358
WebDriverWait(driver, 300).until(
@@ -64,7 +69,7 @@ def get_tokenv2_cookie(self):
6469
if not self.tokenv2_cookie:
6570
try:
6671
self.tokenv2_cookie = self.get_token_from_file()
67-
except Exception as e:
72+
except Exception:
6873
try:
6974
cookies = self.get_cookies_from_login()
7075
self.tokenv2_cookie = get_token_from_cookie(cookies, 'token_v2')

src/arguments/utility.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@
3535

3636
console = Console()
3737

38+
def get_browser_driver():
39+
# Try to install web drivers for one of these browsers
40+
# Chrome, Firefox, Edge (One of them must be installed)
41+
try:
42+
return webdriver.Chrome(ChromeDriverManager().install())
43+
except ValueError:
44+
try:
45+
return webdriver.Firefox(executable_path=
46+
GeckoDriverManager().install())
47+
except ValueError:
48+
try:
49+
return webdriver.Edge(EdgeChromiumDriverManager().\
50+
install())
51+
except ValueError:
52+
print("You do not have one of these supported browsers:" +
53+
"Chrome, Firefox, Edge")
54+
3855
class Playbook():
3956
def __init__(self):
4057
self.key = 'DYNAMIC'
@@ -350,23 +367,6 @@ def get_ans(self, questions_list):
350367
stackoverflow_panel.display_panel(questions_list)
351368
# Support for reddit searching can also be implemented from here
352369

353-
def get_browser_driver(self):
354-
# Try to install web drivers for one of these browsers
355-
# Chrome, Firefox, Edge (One of them must be installed)
356-
try:
357-
return webdriver.Chrome(ChromeDriverManager().install())
358-
except ValueError:
359-
try:
360-
return webdriver.Firefox(executable_path=
361-
GeckoDriverManager().install())
362-
except ValueError:
363-
try:
364-
return webdriver.Edge(EdgeChromiumDriverManager().\
365-
install())
366-
except ValueError:
367-
print("You do not have one of these supported browsers:" +
368-
"Chrome, Firefox, Edge")
369-
370370
# Get an access token and extract to a JSON file "access_token.json"
371371
@classmethod
372372
def setCustomKey(self):
@@ -391,7 +391,7 @@ def setCustomKey(self):
391391
scope=scopes, redirect_uri=redirect_uri)
392392
auth_url, state = stackApps.authorization_url(authorization_url)
393393

394-
driver = self.get_browser_driver()
394+
driver = get_browser_driver()
395395

396396
# Open auth_url in one of the supported browsers
397397
driver.get(auth_url)

0 commit comments

Comments
 (0)