Skip to content

Commit 608ea61

Browse files
authored
Code formated using black (#144)
1 parent 5cfc8ca commit 608ea61

File tree

5 files changed

+76
-62
lines changed

5 files changed

+76
-62
lines changed

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@ language: python
22
python:
33
- "3.4"
44
- "3.5"
5-
- "3.6"
65
before_install:
76
- pip install --upgrade pip
7+
matrix:
8+
include:
9+
- python: '3.6' # Black requires Python 3.6+
10+
install:
11+
- pip install -r requirements.txt
12+
- pip install black
13+
script:
14+
- black --check readit setup.py
15+
- python setup.py install
16+
- python setup.py check -r -s
17+
- pytest
818
install:
919
- pip install -r requirements.txt
1020
script:
11-
- flake8 --ignore=F403,F405,F841,E127,E126,E128,W291,E501 readit setup.py
1221
- python setup.py install
1322
- python setup.py check -r -s
1423
- pytest

readit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from readit.cli import main
2020

21-
if __name__ == '__main__':
21+
if __name__ == "__main__":
2222

2323
"""
2424
This is initial function.

readit/database.py

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828

2929
table = BeautifulTable()
3030
table_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 = "="
3535
table.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 = "="
4040
table_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

readit/view.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@
1919

2020
table = BeautifulTable()
2121
table_tag = BeautifulTable()
22-
table.left_border_char = '|'
23-
table.right_border_char = '|'
24-
table.top_border_char = '='
25-
table.header_separator_char = '='
22+
table.left_border_char = "|"
23+
table.right_border_char = "|"
24+
table.top_border_char = "="
25+
table.header_separator_char = "="
2626
table.column_headers = ["ID", "URL", "TAG", "DATE", "TIME"]
27-
table_tag.left_border_char = '|'
28-
table_tag.right_border_char = '|'
29-
table_tag.top_border_char = '='
30-
table_tag.header_separator_char = '='
27+
table_tag.left_border_char = "|"
28+
table_tag.right_border_char = "|"
29+
table_tag.top_border_char = "="
30+
table_tag.header_separator_char = "="
3131
table_tag.column_headers = ["Available TAGs"]
3232

3333

3434
class ShowResults(object):
3535
"""This class includes methods. Which are used to
3636
show output to the user in table format.
3737
"""
38+
3839
def __init__(self):
3940
pass
4041

@@ -51,8 +52,8 @@ def print_bookmarks(self, all_bookmarks):
5152
print("*" * 24, "\nAlready bookmarked URLs.\n", "*" * 23)
5253
for bookmark in all_bookmarks:
5354
table.append_row(
54-
[bookmark[0], bookmark[1], bookmark[2],
55-
bookmark[3], bookmark[4]])
55+
[bookmark[0], bookmark[1], bookmark[2], bookmark[3], bookmark[4]]
56+
)
5657
print(table)
5758
else:
5859
print("No bookmarks found.")

setup.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,12 @@
33
with open("README.rst") as readme_file:
44
long_description = readme_file.read()
55

6-
install_requires = [
7-
'setuptools',
8-
'requests',
9-
'click',
10-
'beautifultable',
11-
]
6+
install_requires = ["setuptools", "requests", "click", "beautifultable"]
127

138
setup(
149
name="readit",
1510
packages=find_packages(),
16-
entry_points={
17-
'console_scripts': [
18-
'readit = readit.__init__:main',
19-
],
20-
},
11+
entry_points={"console_scripts": ["readit = readit.__init__:main"]},
2112
version="v0.2",
2213
author="Ganesh, Shital, Daivshala",
2314
author_email="[email protected]",
@@ -26,10 +17,10 @@
2617
license="GNU General Public License v3.0",
2718
keywords="clitool bookmark readit",
2819
url="https://github.com/projectreadit/readit",
29-
py_modules=['readit.__init__'],
20+
py_modules=["readit.__init__"],
3021
namespace_packages=[],
3122
include_package_data=True,
3223
zip_safe=False,
3324
install_requires=install_requires,
34-
scripts=['test_readit.py'],
25+
scripts=["test_readit.py"],
3526
)

0 commit comments

Comments
 (0)