2828
2929table = BeautifulTable ()
3030table_tag = BeautifulTable ()
31- table .left_border_char = '|'
32- table .right_border_char = '|'
33- table .top_border_char = '='
34- table .header_separator_char = '='
31+ table .left_border_char = "|"
32+ table .right_border_char = "|"
33+ table .top_border_char = "="
34+ table .header_separator_char = "="
3535table .column_headers = ["ID" , "URL" , "TAG" , "DATE" , "TIME" ]
36- table_tag .left_border_char = '|'
37- table_tag .right_border_char = '|'
38- table_tag .top_border_char = '='
39- table_tag .header_separator_char = '='
36+ table_tag .left_border_char = "|"
37+ table_tag .right_border_char = "|"
38+ table_tag .top_border_char = "="
39+ table_tag .header_separator_char = "="
4040table_tag .column_headers = ["Available TAGs" ]
4141
4242
@@ -64,20 +64,21 @@ def init_db(self, cursor, db):
6464 """
6565
6666 try :
67- config_path = os .path .join (
68- os .path .expanduser ('~' ), ".config/readit" )
67+ config_path = os .path .join (os .path .expanduser ("~" ), ".config/readit" )
6968 if not os .path .exists (config_path ):
7069 os .mkdir (config_path )
7170 except OSError :
72- print (' Error: Creating directory.' + config_path )
71+ print (" Error: Creating directory." + config_path )
7372
7473 databasefile = os .path .join (config_path , "bookmarks.db" )
7574 try :
7675 self .db = sqlite3 .connect (databasefile )
7776 self .cursor = self .db .cursor ()
78- self .cursor .execute ('''CREATE TABLE IF NOT EXISTS bookmarks
77+ self .cursor .execute (
78+ """CREATE TABLE IF NOT EXISTS bookmarks
7979 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
80- url TEXT UNIQUE NOT NULL, tags TEXT, date TEXT, time TEXT)''' )
80+ url TEXT UNIQUE NOT NULL, tags TEXT, date TEXT, time TEXT)"""
81+ )
8182 self .db .commit ()
8283
8384 except sqlite3 .OperationalError :
@@ -104,9 +105,12 @@ def add_url(self, url):
104105 global date
105106 start = datetime .datetime .now ()
106107 time = start .strftime ("%H:%M:%S" )
107- self .cursor .execute ('''
108+ self .cursor .execute (
109+ """
108110 INSERT INTO bookmarks(url, tags, date, time) VALUES (?, ?, ?, ?)
109- ''' , (self .url , "None" , date , time ))
111+ """ ,
112+ (self .url , "None" , date , time ),
113+ )
110114 self .db .commit ()
111115 return True
112116 except Exception as e1 :
@@ -136,12 +140,14 @@ def tag_url(self, tag_name, tagged_url):
136140 start = datetime .datetime .now ()
137141 time = start .strftime ("%H:%M:%S" )
138142 self .cursor .execute (
139- '''INSERT INTO bookmarks(url, tags, date, time)
140- VALUES(?, ?, ?, ?)''' , (self .url , self .tag , date , time ))
143+ """INSERT INTO bookmarks(url, tags, date, time)
144+ VALUES(?, ?, ?, ?)""" ,
145+ (self .url , self .tag , date , time ),
146+ )
141147 self .db .commit ()
142148 return True
143149 except Exception as t :
144- return False
150+ return False
145151
146152 def list_all_tags (self ):
147153 """
@@ -154,7 +160,7 @@ def list_all_tags(self):
154160 """
155161 tag_list = set ()
156162 try :
157- self .cursor .execute (''' SELECT tags FROM bookmarks''' )
163+ self .cursor .execute (""" SELECT tags FROM bookmarks""" )
158164 tags_in_db = self .cursor .fetchall ()
159165 for tags_available in tags_in_db :
160166 tag_list .add (tags_available )
@@ -183,10 +189,12 @@ def delete_url(self, url_id):
183189 try :
184190 self .url_id = url_id
185191 self .cursor .execute (
186- ''' SELECT url FROM bookmarks where id=? ''' , (self .url_id ,))
192+ """ SELECT url FROM bookmarks where id=? """ , (self .url_id ,)
193+ )
187194 deleted_url = self .cursor .fetchone ()
188195 self .cursor .execute (
189- ''' DELETE FROM bookmarks WHERE id=? ''' , (self .url_id ,))
196+ """ DELETE FROM bookmarks WHERE id=? """ , (self .url_id ,)
197+ )
190198 self .db .commit ()
191199 if deleted_url :
192200 return True
@@ -218,10 +226,12 @@ def update_url(self, url_id, url):
218226 self .url_id = url_id
219227 self .url = url
220228 self .cursor .execute (
221- ''' SELECT url FROM bookmarks WHERE id=?''' , (self .url_id ,))
229+ """ SELECT url FROM bookmarks WHERE id=?""" , (self .url_id ,)
230+ )
222231 url_replaced = self .cursor .fetchone ()
223- self .cursor .execute (''' UPDATE bookmarks SET url=? WHERE id=?''' ,
224- (self .url , self .url_id ,))
232+ self .cursor .execute (
233+ """ UPDATE bookmarks SET url=? WHERE id=?""" , (self .url , self .url_id )
234+ )
225235 self .db .commit ()
226236 return True
227237 except Exception as e3 :
@@ -237,8 +247,7 @@ def show_url(self):
237247 A table representing all bookmarks.
238248 """
239249 try :
240- self .cursor .execute (
241- ''' SELECT id, url, tags, date, time FROM bookmarks ''' )
250+ self .cursor .execute (""" SELECT id, url, tags, date, time FROM bookmarks """ )
242251 all_bookmarks = self .cursor .fetchall ()
243252 self .db .commit ()
244253 if all_bookmarks == []:
@@ -266,8 +275,10 @@ def search_by_tag(self, tag):
266275 try :
267276 self .tag = tag
268277 self .cursor .execute (
269- ''' SELECT id, url, tags, date, time
270- FROM bookmarks WHERE tags=?''' , (self .tag ,))
278+ """ SELECT id, url, tags, date, time
279+ FROM bookmarks WHERE tags=?""" ,
280+ (self .tag ,),
281+ )
271282 all_bookmarks = self .cursor .fetchall ()
272283 self .db .commit
273284 if all_bookmarks == []:
@@ -291,7 +302,7 @@ def delete_all_url(self):
291302 self .db .commit ()
292303 return False
293304 else :
294- self .cursor .execute (''' DELETE FROM bookmarks ''' )
305+ self .cursor .execute (""" DELETE FROM bookmarks """ )
295306 self .db .commit ()
296307 return True
297308 except Exception as e5 :
@@ -306,8 +317,7 @@ def check_url_db(self):
306317 bool
307318 It returns TRUE if URL is present in database else False.
308319 """
309- self .cursor .execute (
310- ''' SELECT id, url, tags, date, time FROM bookmarks ''' )
320+ self .cursor .execute (""" SELECT id, url, tags, date, time FROM bookmarks """ )
311321 all_bookmarks = self .cursor .fetchall ()
312322 if all_bookmarks == []:
313323 return True
@@ -331,7 +341,8 @@ def open_url(self, urlid):
331341 try :
332342 self .urlid = urlid
333343 self .cursor .execute (
334- ''' SELECT url FROM bookmarks WHERE id=?''' , (self .urlid ,))
344+ """ SELECT url FROM bookmarks WHERE id=?""" , (self .urlid ,)
345+ )
335346 all_row = self .cursor .fetchone ()
336347 for url in all_row :
337348 webbrowser .open_new (url )
@@ -362,8 +373,8 @@ def export_urls(self):
362373 self .conn = sqlite3 .connect (glob (expanduser (databasefile ))[0 ])
363374 self .cursor = self .conn .cursor ()
364375 self .cursor .execute ("select * from bookmarks" )
365- with open ("exported_bookmarks.csv" , "w" , newline = '' ) as csv_file :
366- csv_writer = csv .writer (csv_file , delimiter = ' \t ' )
376+ with open ("exported_bookmarks.csv" , "w" , newline = "" ) as csv_file :
377+ csv_writer = csv .writer (csv_file , delimiter = " \t " )
367378 csv_writer .writerow ([i [0 ] for i in self .cursor .description ])
368379 csv_writer .writerows (self .cursor )
369380 dirpath = os .getcwd () + "/exported_bookmarks.csv"
@@ -388,8 +399,10 @@ def url_info(self, url):
388399 try :
389400 self .url_exist = url
390401 self .cursor .execute (
391- ''' SELECT id, url, tags, date, time
392- FROM bookmarks WHERE url=?''' , (self .url_exist ,))
402+ """ SELECT id, url, tags, date, time
403+ FROM bookmarks WHERE url=?""" ,
404+ (self .url_exist ,),
405+ )
393406 all_bookmarks = self .cursor .fetchall ()
394407 self .db .commit ()
395408 return all_bookmarks
0 commit comments