1414# You should have received a copy of the GNU General Public License
1515# along with readit. If not, see <http://www.gnu.org/licenses/>.
1616
17-
1817import requests # to check whether url is valid or not
1918import click # used for command line interface.
2019from readit import database # used to perform database operations.
20+ from readit import view # Used to show results to users
2121import sys # used to exit from system
2222
2323database_connection = database .DatabaseConnection ()
24+ output = view .ShowResults ()
2425
2526
2627@click .command ()
3637@click .option ('--export' , '-e' , multiple = True ,
3738 nargs = 0 , help = "Export URLs in csv file" )
3839@click .option ('--taglist' , '-tl' , multiple = True , nargs = 0 , help = "Show all Tags" )
40+ @click .option ('--urlinfo' , '-ui' , nargs = 1 , help = "Check particular URL information" )
3941@click .argument ('insert' , nargs = - 1 , required = False )
4042def main (insert , add , tag , delete , clear ,
41- update , search , view , openurl , version , export , taglist ):
43+ update , search , view , openurl , version , export , taglist , urlinfo ):
4244 """
4345 Readit - Command-line bookmark manager tool.
4446 """
@@ -49,17 +51,31 @@ def main(insert, add, tag, delete, clear,
4951 validate_url = requests .get (url )
5052 validate_code = validate_url .status_code
5153 if validate_code == 200 :
52- database_connection .add_url (url )
54+ is_url_added = database_connection .add_url (url )
55+ if is_url_added :
56+ print ("Bookmarked." )
57+ else :
58+ print ("URL is already bookmarked. Check URL information. See help" )
5359 else :
5460 print ("*" * 12 , "\n Invalid URL\n " , "*" * 11 )
55- option_yes_no (url )
61+ is_url_added = option_yes_no (url )
62+ if is_url_added :
63+ print ("Bookmarked." )
64+ else :
65+ print ("URL is already bookmarked. Check URL information. See help" )
5666 except Exception as e :
5767 print ("*" * 12 , "\n Invalid URL\n " , "*" * 11 )
58- option_yes_no (url )
59-
68+ is_url_added = option_yes_no (url )
69+ if is_url_added :
70+ print ("Bookmarked." )
71+ else :
72+ print ("URL is already bookmarked. Check URL information. See help" )
6073 elif delete :
61- database_connection .delete_url (delete )
62-
74+ is_url_deleted = database_connection .delete_url (delete )
75+ if is_url_deleted :
76+ print ("URL deleted." )
77+ else :
78+ print ("URL of this id is not present in database." )
6379 elif update :
6480 url_list = []
6581 for update_to_url in update :
@@ -70,22 +86,37 @@ def main(insert, add, tag, delete, clear,
7086 validate_url = requests .get (url )
7187 validate_code = validate_url .status_code
7288 if validate_code == 200 :
73- database_connection .update_url (url_id , url )
89+ is_url_updated = database_connection .update_url (url_id , url )
90+ if is_url_updated :
91+ print ("URL of this id updated." )
92+ else :
93+ print ("Provided id is not present or same URL is already in available." )
7494 else :
7595 print ("*" * 12 , "\n Invalid URL\n " , "*" * 11 )
76- update_option_yes_no (url_id , url )
96+ is_url_updated = update_option_yes_no (url_id , url )
97+ if is_url_updated :
98+ print ("URL of this id updated." )
99+ else :
100+ print ("Provided id is not present or same URL is already in available." )
77101 except Exception as e :
78102 print ("*" * 12 , "\n Invalid URL\n " , "*" * 11 )
79- update_option_yes_no (url_id , url )
80-
103+ is_url_updated = update_option_yes_no (url_id , url )
104+ if is_url_updated :
105+ print ("URL of this id updated." )
106+ else :
107+ print ("Provided id is not present or same URL is already in available." )
81108 elif view :
82- database_connection .show_url ()
109+ output . print_bookmarks ( database_connection .show_url () )
83110 elif openurl :
84111 database_connection .open_url (openurl )
85112 elif search :
86- database_connection .search_by_tag (search )
113+ output . print_bookmarks ( database_connection .search_by_tag (search ) )
87114 elif clear :
88- database_connection .delete_all_url ()
115+ is_db_clear = database_connection .delete_all_url ()
116+ if is_db_clear :
117+ print ("All bookmarks deleted." )
118+ else :
119+ print ("Database does not have any data." )
89120 elif tag :
90121 tag_list = []
91122 for tag_to_url in tag :
@@ -96,33 +127,66 @@ def main(insert, add, tag, delete, clear,
96127 validate_url = requests .get (tagged_url )
97128 validate_code = validate_url .status_code
98129 if validate_code == 200 :
99- database_connection .tag_url (tag_name , tagged_url )
130+ is_url_tagged = database_connection .tag_url (tag_name , tagged_url )
131+ if is_url_tagged :
132+ print ("Bookmarked URL with tag." )
133+ else :
134+ print ("URL is already bookmarked with tag. Check URL information. See help" )
100135 else :
101136 print ("*" * 12 , "\n Invalid URL\n " , "*" * 11 )
102- tag_option_yes_no (tag_name , tagged_url )
137+ is_url_tagged = tag_option_yes_no (tag_name , tagged_url )
138+ if is_url_tagged :
139+ print ("Bookmarked URL with tag." )
140+ else :
141+ print ("URL is already bookmarked with tag. Check URL information. See help" )
103142 except Exception as t :
104143 print ("*" * 12 , "\n Invalid URL\n " , "*" * 11 )
105- tag_option_yes_no (tag_name , tagged_url )
144+ is_url_tagged = tag_option_yes_no (tag_name , tagged_url )
145+ if is_url_tagged :
146+ print ("Bookmarked URL with tag." )
147+ else :
148+ print ("URL is already bookmarked with tag. Check URL information. See help" )
106149 elif taglist :
107- database_connection .list_all_tags ()
150+ output . print_all_tags ( database_connection .list_all_tags () )
108151 elif version :
109- print ("readit v0.2 " )
152+ print ("readit v0.3 " )
110153 elif export :
111- database_connection .export_urls ()
154+ path = database_connection .export_urls ()
155+ msg = "Exported bookmarks available at"
156+ if path :
157+ path = "{0} {1}" .format (msg , path )
158+ print (path )
159+ else :
160+ print ("Bookmarks are not exported in csv file." )
161+ elif urlinfo :
162+ output .print_bookmarks (database_connection .url_info (urlinfo ))
112163 else :
113164 for url_to_add in insert :
114165 url = url_to_add
115166 try :
116167 validate_url = requests .get (url )
117168 validate_code = validate_url .status_code
118169 if validate_code == 200 :
119- database_connection .add_url (url )
170+ is_url_added = database_connection .add_url (url )
171+ if is_url_added :
172+ print ("Bookmarked." )
173+ else :
174+ print ("URL is already bookmarked. Check URL information. See help" )
120175 else :
121176 print ("*" * 12 , "\n Invalid URL\n " , "*" * 11 )
122- option_yes_no (url )
177+ is_url_added = option_yes_no (url )
178+ if is_url_added :
179+ print ("Bookmarked." )
180+ else :
181+ print ("URL is already bookmarked. Check URL information. See help" )
182+
123183 except Exception as e :
124184 print ("*" * 12 , "\n Invalid URL\n " , "*" * 11 )
125- option_yes_no (url )
185+ is_url_added = option_yes_no (url )
186+ if is_url_added :
187+ print ("Bookmarked." )
188+ else :
189+ print ("URL is already bookmarked. Check URL information. See help" )
126190
127191
128192def option_yes_no (url ):
@@ -131,7 +195,7 @@ def option_yes_no(url):
131195 """
132196 option = input ("Still you want to bookmark: Yes/No ? " )
133197 if option .lower () in ['yes' , 'y' ]:
134- database_connection .add_url (url )
198+ return database_connection .add_url (url )
135199 else :
136200 sys .exit (0 )
137201
@@ -140,9 +204,9 @@ def tag_option_yes_no(tag_name, tagged_url):
140204 """
141205 Asks whether to tag and bookmark invalid URLs or Offline URLs.
142206 """
143- option = input ("Still you want to update : Yes/No ? " )
207+ option = input ("Still you want to bookmark : Yes/No ? " )
144208 if option .lower () in ['yes' , 'y' ]:
145- database_connection .tag_url (tag_name , tagged_url )
209+ return database_connection .tag_url (tag_name , tagged_url )
146210 else :
147211 sys .exit (0 )
148212
@@ -153,4 +217,4 @@ def update_option_yes_no(url_id, url):
153217 """
154218 option = input ("Still you want to update: Yes/No ? " )
155219 if option .lower () in ['yes' , 'y' ]:
156- database_connection .update_url (url_id , url )
220+ return database_connection .update_url (url_id , url )
0 commit comments