@@ -56,11 +56,6 @@ def init_db(self, cursor, db):
5656 creates or opens file mydatabase with sqlite3 DataBase.
5757 get cursor object.
5858 create table.
59-
60- Attributes
61- ----------
62- db : sqlite database connection.
63- cursor : sqlite database cursor.
6459 """
6560
6661 try :
@@ -87,17 +82,6 @@ def init_db(self, cursor, db):
8782 def add_url (self , url ):
8883 """
8984 URL will be adding to database.
90-
91-
92- Parameters
93- ----------
94- url : str
95- A URL to add in database.
96-
97- Returns
98- -------
99- str
100- A URL inserted in database.
10185 """
10286
10387 try :
@@ -119,19 +103,6 @@ def add_url(self, url):
119103 def tag_url (self , tag_name , tagged_url ):
120104 """
121105 URLs can be added by respective Tags.
122-
123- Parameters
124- ----------
125- tag_name : str
126- A comma separated tag to URL.
127-
128- tagged_url : str
129- A URL to be tagged.
130-
131- Returns
132- -------
133- str
134- A URL inserted with tag.
135106 """
136107 self .tag = tag_name
137108 self .url = tagged_url
@@ -152,11 +123,6 @@ def tag_url(self, tag_name, tagged_url):
152123 def list_all_tags (self ):
153124 """
154125 Shows list of all available Tags in database.
155-
156- Returns
157- -------
158- list
159- It returns all available Tags associated with URLs in database.
160126 """
161127 tag_list = set ()
162128 try :
@@ -175,16 +141,6 @@ def list_all_tags(self):
175141 def delete_url (self , url_id ):
176142 """
177143 URLs can deleted as per id number provided.
178-
179- Parameters
180- ----------
181- urlid : int
182- id of url present in database.
183-
184- Returns
185- -------
186- str
187- A URL deleted from database.
188144 """
189145 try :
190146 self .url_id = url_id
@@ -206,19 +162,6 @@ def delete_url(self, url_id):
206162 def update_url (self , url_id , url ):
207163 """
208164 URLs can be updated with respect to id.
209-
210- Parameters
211- ----------
212- url_id : int
213- id of url which present in database.
214-
215- url : str
216- A URL to update.
217-
218- Returns
219- -------
220- str
221- A URL updated in database.
222165 """
223166
224167 try :
@@ -240,11 +183,6 @@ def update_url(self, url_id, url):
240183 def show_url (self ):
241184 """
242185 All URLs from database displayed to user on screen.
243-
244- Returns
245- -------
246- list
247- A table representing all bookmarks.
248186 """
249187 try :
250188 self .cursor .execute (""" SELECT id, url, tags, date, time FROM bookmarks """ )
@@ -257,29 +195,28 @@ def show_url(self):
257195 except Exception as e4 :
258196 return None
259197
260- def search_by_tag (self , tag ):
198+ def search_url (self , search_value ):
261199 """
262- Group of URLs displayed with respect to Tag.
263-
264- Parameters
265- ----------
266- tag : str
267- tag to search URLs.
268-
269- Returns
270- -------
271- list
272- A table containing bookmarks.
200+ Group of URLs displayed with respect to search_value.
273201
274202 """
275203 try :
276- self .tag = tag
277- self .cursor .execute (
278- """ SELECT id, url, tags, date, time
279- FROM bookmarks WHERE tags=?""" ,
280- (self .tag ,),
281- )
282- all_bookmarks = self .cursor .fetchall ()
204+ self .search = search_value
205+ all_bookmarks = []
206+ if self .check_tag (search_value ):
207+ self .cursor .execute (
208+ """ SELECT id, url, tags, date, time
209+ FROM bookmarks WHERE tags=?""" ,
210+ (self .search ,),
211+ )
212+ all_bookmarks = self .cursor .fetchall ()
213+
214+ else :
215+ self .cursor .execute (""" SELECT * FROM bookmarks""" )
216+ bookmarks = self .cursor .fetchall ()
217+ for bookmark in bookmarks :
218+ if search_value .lower () in bookmark [1 ]:
219+ all_bookmarks .append (bookmark )
283220 self .db .commit
284221 if all_bookmarks == []:
285222 return None
@@ -291,11 +228,6 @@ def search_by_tag(self, tag):
291228 def delete_all_url (self ):
292229 """
293230 All URLs from database will be deleted.
294-
295- Returns
296- -------
297- null
298- All URLs will be removed from database.
299231 """
300232 try :
301233 if self .check_url_db ():
@@ -311,11 +243,6 @@ def delete_all_url(self):
311243 def check_url_db (self ):
312244 """
313245 Checks Whether URL is present in database or not.
314-
315- Returns
316- -------
317- bool
318- It returns TRUE if URL is present in database else False.
319246 """
320247 self .cursor .execute (""" SELECT id, url, tags, date, time FROM bookmarks """ )
321248 all_bookmarks = self .cursor .fetchall ()
@@ -324,41 +251,66 @@ def check_url_db(self):
324251 else :
325252 return False
326253
327- def open_url (self , urlid ):
254+ def open_url (self , url_id_tag ):
328255 """
329- Opens the URL in default browser.
330-
331- Parameters
332- ----------
333- urlid:
334- id of url present in database.
256+ Opens the URLs in default browser.
257+ """
258+ try :
259+ if self .check_id (url_id_tag ):
260+ all_row = self .check_id (url_id_tag )
261+ elif self .search_url (url_id_tag ):
262+ all_rows = self .search_url (url_id_tag )
263+ for bookmark in all_rows :
264+ webbrowser .open (bookmark [1 ])
265+ self .db .commit ()
266+ return True
267+ else :
268+ print (
269+ "Provide either valid url id or url tag name or any valid substring."
270+ )
271+
272+ if all_row :
273+ for i in range (len (all_row )):
274+ for url in all_row [i ]:
275+ webbrowser .open_new_tab (url )
276+ self .db .commit ()
277+ return True
278+ except Exception as i :
279+ return False
335280
336- Returns
337- -------
338- str
339- A URL opened in default browser.
281+ def check_tag (self , url_tag ):
282+ """
283+ Checks this tag is available in database.
340284 """
341285 try :
342- self .urlid = urlid
343286 self .cursor .execute (
344- """ SELECT url FROM bookmarks WHERE id =?""" , (self . urlid ,)
287+ """ SELECT url FROM bookmarks WHERE tags =?""" , (url_tag ,)
345288 )
346- all_row = self .cursor .fetchone ()
347- for url in all_row :
348- webbrowser .open_new (url )
289+ all_row = self .cursor .fetchall ()
349290 self .db .commit ()
350- return True
291+ if all_row == []:
292+ return None
293+ return all_row
351294 except Exception as i :
352- return False
295+ return None
296+
297+ def check_id (self , url_id ):
298+ """
299+ Check this is available in database.
300+ """
301+ try :
302+ self .cursor .execute (""" SELECT url FROM bookmarks WHERE id=?""" , (url_id ,))
303+ all_row = self .cursor .fetchall ()
304+ if all_row == []:
305+ return None
306+ self .db .commit ()
307+ return all_row
308+ except Exception as i :
309+ return None
353310
354311 def export_urls (self ):
355312 """
356313 Exporting urls to csv file from database.
357-
358- Returns
359- -------
360- csv file
361- A file containing exported bookmarks records.
362314 """
363315 try :
364316 config_path = os .path .expanduser ("~/.config/readit" )
@@ -385,16 +337,6 @@ def export_urls(self):
385337 def url_info (self , url ):
386338 """
387339 Display the information regarding already present URL in database.
388-
389- Parameters
390- ----------
391- url : str
392- url to search it's information from database.
393-
394- Returns
395- -------
396- str
397- All the information about particular URL.
398340 """
399341 try :
400342 self .url_exist = url
0 commit comments