Skip to content

Commit 5b097aa

Browse files
Merge pull request #139 from pranavbaburaj/master
fix:Add dependencies to setup.py
2 parents f802b93 + ac662f1 commit 5b097aa

File tree

10 files changed

+268
-207
lines changed

10 files changed

+268
-207
lines changed

dynamic/__main__.py

Lines changed: 58 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,86 +7,77 @@
77
version = "0.1.0"
88

99
parser = argparse.ArgumentParser()
10-
parser.add_argument("-st",
11-
"--start",
12-
help="introduce you to dynamic",
13-
action="store_true")
14-
15-
parser.add_argument("-s",
16-
"--search",
17-
help="search a question on StackOverflow",
18-
action="store_true")
19-
20-
parser.add_argument("-v",
21-
"--version",
22-
version=f"Dynamic-CLI version {version}",
23-
action='version')
24-
25-
26-
parser.add_argument("-n",
27-
"--new",
28-
help="Opens browser to create new StackOverflow question.",
29-
const=True,
30-
metavar="title (optional)",
31-
nargs="?")
32-
33-
parser.add_argument("-file",
34-
"--file",
35-
help="Save answer to a file",
36-
action="store_true")
37-
38-
parser.add_argument("-c",
39-
"--custom",
40-
help="Set a custom API key",
41-
action="store_true")
42-
43-
parser.add_argument("-u",
44-
"--update",
45-
help="Check updates for the application",
46-
action="store_true")
47-
48-
parser.add_argument("-GET",
49-
help="Make a GET request to an API",
50-
action='store_true')
51-
52-
parser.add_argument("-POST",
53-
help="Make a POST request to an API",
54-
action='store_true')
55-
56-
parser.add_argument("-DELETE",
57-
help = "Make a DELETE request to an API",
58-
action = 'store_true')
59-
60-
parser.add_argument("-p",
61-
"--playbook",
62-
help="View and organise the playbook",
63-
action='store_true')
64-
65-
parser.add_argument("-no",
66-
"--notion",
67-
help="\
10+
parser.add_argument(
11+
"-st", "--start", help="introduce you to dynamic", action="store_true"
12+
)
13+
14+
parser.add_argument(
15+
"-s", "--search", help="search a question on StackOverflow", action="store_true"
16+
)
17+
18+
parser.add_argument(
19+
"-v", "--version", version=f"Dynamic-CLI version {version}", action="version"
20+
)
21+
22+
23+
parser.add_argument(
24+
"-n",
25+
"--new",
26+
help="Opens browser to create new StackOverflow question.",
27+
const=True,
28+
metavar="title (optional)",
29+
nargs="?",
30+
)
31+
32+
parser.add_argument(
33+
"-file", "--file", help="Save answer to a file", action="store_true"
34+
)
35+
36+
parser.add_argument("-c", "--custom", help="Set a custom API key", action="store_true")
37+
38+
parser.add_argument(
39+
"-u", "--update", help="Check updates for the application", action="store_true"
40+
)
41+
42+
parser.add_argument("-GET", help="Make a GET request to an API", action="store_true")
43+
44+
parser.add_argument("-POST", help="Make a POST request to an API", action="store_true")
45+
46+
parser.add_argument(
47+
"-DELETE", help="Make a DELETE request to an API", action="store_true"
48+
)
49+
50+
parser.add_argument(
51+
"-p", "--playbook", help="View and organise the playbook", action="store_true"
52+
)
53+
54+
parser.add_argument(
55+
"-no",
56+
"--notion",
57+
help="\
6858
Login to your Notion account to save playbook.\
6959
Opens a browser window for you to login to\
7060
your Notion accout",
71-
action='store_true')
61+
action="store_true",
62+
)
7263

7364
ARGV = parser.parse_args()
7465

7566
search_flag = Search(ARGV)
7667

68+
7769
def main():
78-
if ARGV.start:
79-
print('''\U0001F604 Hello and Welcome to Dynamic CLI
70+
if ARGV.start:
71+
print(
72+
"""\U0001F604 Hello and Welcome to Dynamic CLI
8073
\U0001F917 Use the following commands to get started
8174
\U0001F50E Search on StackOverflow with '-s'
8275
\U0001F4C4 Open browser to create new Stack Overflow question with '-n [title(optional)]'
8376
\U0001F4C2 Save answer to a file with '-file'
8477
\U00002728 Know the version of Dynamic CLI with '-V'
8578
\U0001F609 See this message again with '-st'
8679
\U00002755 Get help with '-h'
87-
''')
88-
else:
89-
search_flag.search_args()
90-
91-
92-
80+
"""
81+
)
82+
else:
83+
search_flag.search_args()

dynamic/api_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def enter_data_payload(cls):
7676
try:
7777
data = json.loads(data)
7878
except Exception as exception_obj:
79-
print(f"Unable to load the data due to {exception_obj}, please try again \n")
79+
print(
80+
f"Unable to load the data due to {exception_obj}, please try again \n"
81+
)
8082
cls.enter_data_payload()
8183
elif store == 2:
8284
data = cls.read_data_from_file()

dynamic/error.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from termcolor import colored
22

33

4-
class SearchError():
4+
class SearchError:
55
def __init__(self, error_statement, suggestion="Try again"):
66
# the error statement
77
self.error_statement = error_statement
@@ -13,13 +13,14 @@ def __init__(self, error_statement, suggestion="Try again"):
1313

1414
def evoke_search_error(self, error_statement):
1515
print_text = [
16-
colored(error_statement, 'red'),
17-
colored(self.suggestion, 'green')
16+
colored(error_statement, "red"),
17+
colored(self.suggestion, "green"),
1818
]
1919
for text_to_print in print_text:
2020
print(text_to_print)
2121

22-
class LoginError():
22+
23+
class LoginError:
2324
def __init__(self, error_statement, success=False):
2425
"""
2526
Implements error printing for User Login

dynamic/notion.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,41 @@
99
from selenium.webdriver.support.ui import WebDriverWait
1010
from selenium.webdriver.support import expected_conditions as EC
1111

12+
1213
def get_token_from_cookie(cookie, token):
1314
for el in cookie:
14-
if el['name'] == token:
15+
if el["name"] == token:
1516
return el
1617

18+
1719
def get_token_from_file():
1820
try:
19-
with open(TOKEN_FILE_PATH, 'r') as f:
21+
with open(TOKEN_FILE_PATH, "r") as f:
2022
data = f.read()
2123
except Exception as e:
2224
print(e)
23-
if(not data or data==""):
25+
if not data or data == "":
2426
raise RuntimeError("Token not found in file")
2527
else:
2628
return data
2729

30+
2831
def get_cookies_from_login():
2932
"""Capture browser cookies for authentication."""
3033
driver = get_browser_driver()
3134
try:
3235
driver.get(LOGIN_PATH)
3336
WebDriverWait(driver, 300).until(
34-
EC.presence_of_element_located((By.CLASS_NAME,
35-
"notion-sidebar-container")))
37+
EC.presence_of_element_located((By.CLASS_NAME, "notion-sidebar-container"))
38+
)
3639
return driver.get_cookies()
3740
except Exception as e:
3841
print(e)
3942
finally:
4043
driver.quit()
4144

42-
class NotionClient():
45+
46+
class NotionClient:
4347

4448
"""
4549
Implements Login and token retrieval.
@@ -48,6 +52,7 @@ class NotionClient():
4852
generating Notion's tokenv2_cookie, storing it locally and uploading
4953
content to User's space
5054
"""
55+
5156
def __init__(self):
5257
"""
5358
No input parameters required for instatiating object.
@@ -56,11 +61,11 @@ def __init__(self):
5661
:tokenv2_key: used to create environment variable
5762
"""
5863
self.tokenv2_cookie = None
59-
self.tokenv2_key = 'TOKENV2'
64+
self.tokenv2_key = "TOKENV2"
6065

6166
def save_token_file(self):
62-
if(self.tokenv2_cookie):
63-
with open(TOKEN_FILE_PATH, 'w') as f:
67+
if self.tokenv2_cookie:
68+
with open(TOKEN_FILE_PATH, "w") as f:
6469
f.write(str(self.tokenv2_cookie))
6570

6671
def get_tokenv2_cookie(self):
@@ -74,7 +79,7 @@ def get_tokenv2_cookie(self):
7479
except Exception:
7580
try:
7681
cookies = get_cookies_from_login()
77-
self.tokenv2_cookie = get_token_from_cookie(cookies, 'token_v2')
82+
self.tokenv2_cookie = get_token_from_cookie(cookies, "token_v2")
7883
except Exception:
7984
self.tokenv2_cookie = None
8085
finally:

dynamic/save.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ def __init__(self, result_json):
1111
self.save_data_to_file(self.result_json, self.save_results_filename)
1212

1313
def save_data_to_file(self, data, filename):
14-
with open(os.path.join(os.getcwd(), f"{filename}.json"),
15-
"w") as result_writer:
14+
with open(os.path.join(os.getcwd(), f"{filename}.json"), "w") as result_writer:
1615
json.dump(data, result_writer, indent=6)
1716

1817
def __get_as_dict(self, json_array):
@@ -30,4 +29,4 @@ def generate_file_name(self, directory):
3029
return filename
3130

3231
def __repr__(self):
33-
return str(self.save_results_filename)
32+
return str(self.save_results_filename)

dynamic/search.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212
from .notion import NotionClient
1313

1414
version = "0.1.0"
15-
class Prompt():
15+
16+
17+
class Prompt:
1618
def __init__(self, message):
1719
self.message = message
1820

1921
def prompt(self):
20-
print(colored(f"{self.message} : ", 'cyan'), end='')
22+
print(colored(f"{self.message} : ", "cyan"), end="")
2123
data = input()
2224
return data
2325

2426

25-
class Search():
27+
class Search:
2628
def __init__(self, arguments):
2729
self.arguments = arguments
2830
self.utility_object = Utility()
@@ -69,24 +71,28 @@ def search_for_results(self, save=False):
6971
if each_query == "Tags":
7072
continue
7173
if prompt.strip() == "":
72-
SearchError("\U0001F613 Input data empty",
73-
"\U0001F504 Please try again ")
74+
SearchError(
75+
"\U0001F613 Input data empty", "\U0001F504 Please try again "
76+
)
7477
sys.exit()
7578
except:
7679
sys.exit()
7780

7881
query_solutions.append(prompt)
7982

80-
question, tags = query_solutions[0], query_solutions[1] if len(query_solutions) > 1 else ""
83+
question, tags = (
84+
query_solutions[0],
85+
query_solutions[1] if len(query_solutions) > 1 else "",
86+
)
8187
json_output = self.utility_object.make_request(question, tags)
8288
questions = self.utility_object.get_que(json_output)
8389
if questions == []:
8490
# evoke an error
85-
SearchError("\U0001F613 No answer found",
86-
"\U0001F604 Please try reddit")
91+
SearchError("\U0001F613 No answer found", "\U0001F604 Please try reddit")
8792
else:
8893
data = self.utility_object.get_ans(questions)
89-
print('''
94+
print(
95+
"""
9096
\U0001F604 Hopefully you found what you were looking for!
9197
\U0001F4C2 You can save an answer to a file with '-file'
9298
@@ -95,12 +101,17 @@ def search_for_results(self, save=False):
95101
on StackOverflow with '-n [title (optional)]'
96102
97103
\U0001F50E To search more use '-s'
98-
''')
104+
"""
105+
)
99106

100107
if save:
101108
filename = SaveSearchResults(data)
102109
print(
103-
colored(f"\U0001F604 Answers successfully saved into {filename}",
104-
"green"),
105-
colored("\U0001F604 Answers successfully saved into" +\
106-
filename, "green"))
110+
colored(
111+
f"\U0001F604 Answers successfully saved into {filename}",
112+
"green",
113+
),
114+
colored(
115+
"\U0001F604 Answers successfully saved into" + filename, "green"
116+
),
117+
)

dynamic/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
except FileExistsError:
1515
pass
1616

17-
if(not os.path.isfile(TOKEN_FILE_PATH)):
18-
open(TOKEN_FILE_PATH, 'w').close()
17+
if not os.path.isfile(TOKEN_FILE_PATH):
18+
open(TOKEN_FILE_PATH, "w").close()

0 commit comments

Comments
 (0)