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 )
4156def 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\n Error: URL not provided. Please use the following format: readit -a <url> -t <tag>\033 [0m" )
79+ print (
80+ """\033 [91m\n Error: 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\n Success! Bookmarked URL `{ url } ` with tag `{ tag } `. 🎉\033 [0m" )
7391 else :
74- print ("\033 [93m\n Warning: The URL seems to be inaccessible at the moment.\033 [0m" ) # Warning in yellow
92+ print (
93+ "\033 [93m\n Warning: 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\n Success! Bookmarked URL `{ url } ` with tag `{ tag } `. 🎉\033 [0m" )
98+ print (
99+ f"\033 [92m\n Success! Bookmarked URL `{ url } ` with tag `{ tag } `. 🎉\033 [0m"
100+ )
79101 except Exception :
80- print ("\033 [93m\n Warning: The URL seems to be inaccessible at the moment.\033 [0m" ) # Warning in yellow
102+ print (
103+ "\033 [93m\n Warning: 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\n Success! 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\n Warning: The URL seems to be inaccessible at the moment.\033 [0m" ) # Warning in yellow
123+ print (
124+ "\033 [93m\n Warning: 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\n Warning: The URL seems to be inaccessible at the moment.\033 [0m" ) # Warning in yellow
129+ print (
130+ "\033 [93m\n Warning: 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\n Warning: The URL seems to be inaccessible at the moment.\033 [0m" ) # Warning in yellow
169+ print (
170+ "\033 [93m\n Warning: 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\n Warning: The URL seems to be inaccessible at the moment.\033 [0m" ) # Warning in yellow
180+ print (
181+ "\033 [93m\n Warning: 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
148192def option_yes_no ():
149193 """
@@ -155,12 +199,13 @@ def option_yes_no():
155199 else :
156200 sys .exit (0 )
157201
202+
158203def check_url_validation (url_given ):
159204 url = url_given .strip () # Strip any leading/trailing whitespace
160205 if not url :
161206 print ("\033 [91m\n Error: 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