Skip to content

Commit 7ba0cc4

Browse files
committed
Add Login success/failure messages
1 parent 6e57396 commit 7ba0cc4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/arguments/error.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,18 @@ def evoke_search_error(self, error_statement):
1818
]
1919
for text_to_print in print_text:
2020
print(text_to_print)
21+
22+
class LoginError():
23+
def __init__(self, error_statement, success=False):
24+
# the error statement
25+
self.error_statement = error_statement
26+
27+
# success determines the color of message
28+
self.success = success
29+
30+
self.evoke_search_error()
31+
32+
def evoke_search_error(self):
33+
color = "green" if self.success else "red"
34+
print_text = colored(self.error_statement, color)
35+
print(print_text)

src/arguments/notion.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import os
22

33
from .utility import get_browser_driver
4+
from .error import LoginError
45
from .settings import LOGIN_PATH
56
from .settings import TOKEN_FILE_PATH
67

78
from selenium.webdriver.common.by import By
89
from selenium.webdriver.support.ui import WebDriverWait
910
from selenium.webdriver.support import expected_conditions as EC
1011

12+
from rich import console
13+
1114
def get_token_from_cookie(cookie, token):
1215
for el in cookie:
1316
if el['name'] == token:
@@ -72,17 +75,18 @@ def get_tokenv2_cookie(self):
7275
if not self.tokenv2_cookie:
7376
try:
7477
self.tokenv2_cookie = get_token_from_file()
78+
LoginError("Login Successful", success=True)
7579
except Exception:
7680
try:
7781
cookies = get_cookies_from_login()
7882
self.tokenv2_cookie = get_token_from_cookie(cookies, 'token_v2')
7983
except Exception as e:
80-
print(e)
8184
self.tokenv2_cookie = None
8285
finally:
8386
if self.tokenv2_cookie:
8487
os.environ[self.tokenv2_key] = str(self.tokenv2_cookie)
88+
LoginError("Login Successful", success=True)
8589
self.save_token_file()
8690
else:
87-
raise RuntimeError("Cookie unreachable")
91+
LoginError("Login Failed", success=False)
8892
return self.get_tokenv2_cookie

0 commit comments

Comments
 (0)