Skip to content

Commit ab22502

Browse files
authored
Merge pull request #172 from pythonpune/formatcode
Formatting code with pre-commit configurations settings
2 parents 44c3e28 + de8ef0f commit ab22502

File tree

7 files changed

+179
-96
lines changed

7 files changed

+179
-96
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Pre-Commit and Cross-Platform Test Suite
22

33
on:
4-
pull_request:
4+
pull_request:
55
branches:
66
- master
77
types:
@@ -12,7 +12,7 @@ on:
1212
# Run every Friday at 23:59 UTC
1313
- cron: '59 23 * * 5'
1414
workflow_dispatch:
15-
15+
1616
jobs:
1717
pre-commit:
1818
name: Pre-Commit Checks

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
name: Reorder Python Imports
2525
language_version: python3
2626
- repo: https://github.com/psf/black
27-
rev: 20.8b1
27+
rev: 22.12.0
2828
hooks:
2929
- id: black
3030
name: Formate with Black

docs/conf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@
5252
master_doc = "index"
5353

5454
# General information about the project.
55-
project = u"readit"
56-
copyright = u"2018, projectreadit organization"
57-
author = u"projectreadit organization"
55+
project = "readit"
56+
copyright = "2018, projectreadit organization"
57+
author = "projectreadit organization"
5858

5959
# The version info for the project you're documenting, acts as replacement for
6060
# |version| and |release|, also used in various other places throughout the
6161
# built documents.
6262
#
6363
# The short X.Y version.
64-
version = u""
64+
version = ""
6565
# The full version, including alpha/beta/rc tags.
66-
release = u"v0.2"
66+
release = "v0.2"
6767

6868
# The language for content autogenerated by Sphinx. Refer to documentation
6969
# for a list of supported languages.
@@ -145,15 +145,15 @@
145145
# (source start file, target name, title,
146146
# author, documentclass [howto, manual, or own class]).
147147
latex_documents = [
148-
(master_doc, "readit.tex", u"readit Documentation", u"projectreadit organization", "manual"),
148+
(master_doc, "readit.tex", "readit Documentation", "projectreadit organization", "manual"),
149149
]
150150

151151

152152
# -- Options for manual page output ---------------------------------------
153153

154154
# One entry per manual page. List of tuples
155155
# (source start file, name, description, authors, manual section).
156-
man_pages = [(master_doc, "readit", u"readit Documentation", [author], 1)]
156+
man_pages = [(master_doc, "readit", "readit Documentation", [author], 1)]
157157

158158

159159
# -- Options for Texinfo output -------------------------------------------
@@ -165,7 +165,7 @@
165165
(
166166
master_doc,
167167
"readit",
168-
u"readit Documentation",
168+
"readit Documentation",
169169
author,
170170
"readit",
171171
"One line description of project.",

readit/cli.py

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,27 @@
3030
@click.option("--tag", "-t", help="Use to tag url --> readit -a <url1> -t <tag1>")
3131
@click.option("--delete", "-d", help="Remove a URL of particular ID --> readit -d <url_id>")
3232
@click.option("--clear", "-c", nargs=0, help="Clear bookmarks --> readit -c")
33-
@click.option("--update", "-u", help="Update a URL for specific ID --> readit -u <existing_id> <new_url>")
34-
@click.option("--search", "-s", help="Search for bookmarks using either a tag or a substring of the URL --> readit -s <tag> or <substring>")
33+
@click.option(
34+
"--update", "-u", help="Update a URL for specific ID --> readit -u <existing_id> <new_url>"
35+
)
36+
@click.option(
37+
"--search",
38+
"-s",
39+
help="""
40+
Search for bookmarks using either a tag or a substring of the URL
41+
--> readit -s <tag> or <substring>
42+
""",
43+
)
3544
@click.option("--view", "-v", multiple=True, nargs=0, help="Show bookmarks --> readit -v")
36-
@click.option("--openurl", "-o", help="Open a URL in your browser by entering a part of the URL. --> readit -o <url_substring>")
45+
@click.option(
46+
"--openurl",
47+
"-o",
48+
help="Open a URL in your browser by entering a part of the URL. --> readit -o <url_substring>",
49+
)
3750
@click.option("--version", "-V", is_flag=True, help="Check latest version --> readit -V")
38-
@click.option("--export", "-e", multiple=True, nargs=0, help="Export URLs in csv file --> readit -e")
51+
@click.option(
52+
"--export", "-e", multiple=True, nargs=0, help="Export URLs in csv file --> readit -e"
53+
)
3954
@click.option("--taglist", "-tl", multiple=True, nargs=0, help="Show all Tags --> readit -tl")
4055
@click.argument("insert", nargs=-1, required=False)
4156
def main(
@@ -61,7 +76,10 @@ def main(
6176
if not tag:
6277
tag = "general" # Default tag if none provided
6378
if not url:
64-
print("\033[91m\nError: URL not provided. Please use the following format: readit -a <url> -t <tag>\033[0m")
79+
print(
80+
"""\033[91m\nError: URL not provided. Please use the following format:
81+
readit -a <url> -t <tag>\033[0m"""
82+
)
6583
sys.exit(0)
6684
try:
6785
validate_code = check_url_validation(url)
@@ -71,19 +89,25 @@ def main(
7189
if is_url_added:
7290
print(f"\033[92m\nSuccess! Bookmarked URL `{url}` with tag `{tag}`. 🎉\033[0m")
7391
else:
74-
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
92+
print(
93+
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
94+
) # Warning in yellow
7595
if option_yes_no():
7696
is_url_added = database_connection.tag_url(url, tag)
7797
if is_url_added:
78-
print(f"\033[92m\nSuccess! Bookmarked URL `{url}` with tag `{tag}`. 🎉\033[0m")
98+
print(
99+
f"\033[92m\nSuccess! Bookmarked URL `{url}` with tag `{tag}`. 🎉\033[0m"
100+
)
79101
except Exception:
80-
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
102+
print(
103+
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
104+
) # Warning in yellow
81105
if option_yes_no():
82106
is_url_added = database_connection.tag_url(url, tag)
83107
if is_url_added:
84108
print(f"\033[92m\nSuccess! Bookmarked URL `{url}` with tag `{tag}`. 🎉\033[0m")
85109
elif delete:
86-
database_connection.delete_url(delete)
110+
database_connection.delete_url(delete)
87111
elif update:
88112
url_list = []
89113
for update_to_url in update:
@@ -96,11 +120,15 @@ def main(
96120
if validate_code == 200:
97121
database_connection.update_url(url_id, url)
98122
else:
99-
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
123+
print(
124+
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
125+
) # Warning in yellow
100126
if option_yes_no():
101127
database_connection.update_url(url_id, url)
102128
except Exception:
103-
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
129+
print(
130+
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
131+
) # Warning in yellow
104132
if option_yes_no():
105133
is_url_updated = database_connection.update_url(url_id, url)
106134
if is_url_updated:
@@ -131,19 +159,35 @@ def main(
131159
if validate_code == 200:
132160
is_url_added = database_connection.add_url(url)
133161
if is_url_added:
134-
print(f"\033[92mSuccess! The URL '{url}' has been successfully bookmarked. 🎉\033[0m")
162+
print(
163+
f"""
164+
\033[92mSuccess! The URL '{url}'
165+
has been successfully bookmarked. 🎉\033[0m
166+
"""
167+
)
135168
else:
136-
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
169+
print(
170+
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
171+
) # Warning in yellow
137172
if option_yes_no():
138173
is_url_added = database_connection.add_url(url)
139174
if is_url_added:
140-
print(f"\033[92mSuccess! The URL '{url}' has been successfully bookmarked. 🎉\033[0m")
175+
print(
176+
f"""\033[92mSuccess! The URL '{url}'
177+
has been successfully bookmarked. 🎉\033[0m"""
178+
)
141179
except Exception:
142-
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
180+
print(
181+
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
182+
) # Warning in yellow
143183
if option_yes_no():
144184
is_url_added = database_connection.add_url(url)
145185
if is_url_added:
146-
print(f"\033[92mSuccess! The URL '{url}' has been successfully bookmarked. 🎉\033[0m")
186+
print(
187+
f"""\033[92mSuccess! The URL '{url}'
188+
has been successfully bookmarked. 🎉\033[0m"""
189+
)
190+
147191

148192
def option_yes_no():
149193
"""
@@ -155,12 +199,13 @@ def option_yes_no():
155199
else:
156200
sys.exit(0)
157201

202+
158203
def check_url_validation(url_given):
159204
url = url_given.strip() # Strip any leading/trailing whitespace
160205
if not url:
161206
print("\033[91m\nError: Cannot add an empty URL.\033[0m")
162207
sys.exit(0)
163-
208+
164209
# Initialize the validation code
165210
validate_code = 0
166211

@@ -174,9 +219,9 @@ def check_url_validation(url_given):
174219
url = full_url # Update URL with valid prefix
175220
break
176221
else:
177-
validate_code = 0
222+
validate_code = 0
178223
else:
179224
# If URL starts with http or https, validate directly
180225
response = requests.get(url)
181226
validate_code = response.status_code
182-
return validate_code
227+
return validate_code

0 commit comments

Comments
 (0)