Skip to content

Commit 2623ed6

Browse files
authored
Merge pull request #166 from pythonpune/multi-tag-#123
Added feature - URL can be tagged with multiple tags
2 parents acee419 + 54be52d commit 2623ed6

File tree

3 files changed

+209
-158
lines changed

3 files changed

+209
-158
lines changed

readit/cli.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
@click.option("--delete", "-d", nargs=1, help="Remove a URL of particular ID")
3232
@click.option("--clear", "-c", multiple=True, nargs=0, help="Clear bookmarks")
3333
@click.option("--update", "-u", nargs=2, help="Update a URL for specific ID")
34-
@click.option("--search", "-s", nargs=1, help="Search all bookmarks by Tag")
34+
@click.option("--search", "-s", nargs=1, help="Search for bookmarks using either a tag or a substring of the URL")
3535
@click.option("--view", "-v", multiple=True, nargs=0, help="Show bookmarks")
36-
@click.option("--openurl", "-o", nargs=1, help="Open URL in Browser")
36+
@click.option("--openurl", "-o", nargs=1, help="Open a URL in your browser by entering a part of the URL.")
3737
@click.option("--version", "-V", is_flag=True, help="Check latest version")
3838
@click.option("--export", "-e", multiple=True, nargs=0, help="Export URLs in csv file")
3939
@click.option("--taglist", "-tl", multiple=True, nargs=0, help="Show all Tags")
40-
@click.option("--urlinfo", "-ui", nargs=1, help="Check particular URL information")
4140
@click.argument("insert", nargs=-1, required=False)
4241
def main(
4342
insert,
@@ -52,66 +51,57 @@ def main(
5251
version,
5352
export,
5453
taglist,
55-
urlinfo,
5654
):
5755
"""
5856
Readit - Command-line bookmark manager tool.
5957
"""
6058
if add:
6159
for url_to_add in add:
62-
url = url_to_add
60+
url = url_to_add.strip() # Strip any leading/trailing whitespace
6361
try:
6462
validate_url = requests.get(url)
6563
validate_code = validate_url.status_code
6664
if validate_code == 200:
6765
is_url_added = database_connection.add_url(url)
6866
if is_url_added:
69-
print(f"\nSuccess: Bookmarked URL `{url}`.")
67+
print(f"\nSuccess: The URL '{url}' has been added to the database.")
7068
else:
7169
print("*" * 12, "\nInvalid URL\n", "*" * 11)
7270
if option_yes_no():
7371
is_url_added = database_connection.add_url(url)
7472
if is_url_added:
75-
print(f"\nSuccess: Bookmarked URL `{url}`.")
73+
print(f"\nSuccess: The URL '{url}' has been added to the database.")
7674
except Exception:
7775
print("*" * 12, "\nInvalid URL\n", "*" * 11)
7876
if option_yes_no():
7977
is_url_added = database_connection.add_url(url)
8078
if is_url_added:
81-
print(f"\nSuccess: Bookmarked URL `{url}`.")
79+
print(f"\nSuccess: The URL '{url}' has been added to the database.")
8280
elif delete:
83-
is_url_deleted = database_connection.delete_url(delete)
84-
delete_url_id = delete
85-
if is_url_deleted:
86-
print(f"\nURL with ID `{delete_url_id}` successfully deleted.")
87-
81+
database_connection.delete_url(delete)
8882
elif update:
8983
url_list = []
9084
for update_to_url in update:
9185
url_list.append(update_to_url)
9286
url_id = url_list[0]
93-
url = url_list[1]
87+
url = url_list[1].strip() # Strip any leading/trailing whitespace
9488
try:
9589
validate_url = requests.get(url)
9690
validate_code = validate_url.status_code
9791
if validate_code == 200:
98-
is_url_updated = database_connection.update_url(url_id, url)
99-
if is_url_updated:
100-
print(f"\nSuccess: URL of ID {url_id} updated.")
92+
database_connection.update_url(url_id, url)
10193
else:
10294
print("*" * 12, "\nInvalid URL\n", "*" * 11)
10395
if option_yes_no():
104-
is_url_updated = database_connection.update_url(url_id, url)
105-
if is_url_updated:
106-
print(f"\nSuccess: URL of ID {url_id} updated.")
96+
database_connection.update_url(url_id, url)
10797
except Exception:
10898
print("*" * 12, "\nInvalid URL\n", "*" * 11)
10999
if option_yes_no():
110100
is_url_updated = database_connection.update_url(url_id, url)
111101
if is_url_updated:
112102
print(f"\nSuccess: URL of ID {url_id} updated.")
113103
elif view:
114-
output.print_bookmarks(database_connection.show_url())
104+
output.print_bookmarks(database_connection.show_urls())
115105
elif openurl:
116106
database_connection.open_url(openurl)
117107
elif search:
@@ -123,7 +113,7 @@ def main(
123113
for tag_to_url in tag:
124114
tag_list.append(tag_to_url)
125115
tag_name = tag_list[0]
126-
tagged_url = tag_list[1]
116+
tagged_url = tag_list[1].strip() # Strip any leading/trailing whitespace
127117
try:
128118
validate_url = requests.get(tagged_url)
129119
validate_code = validate_url.status_code
@@ -153,31 +143,29 @@ def main(
153143
print(f"\nExported bookmarks available at `{path}`")
154144
else:
155145
print("\nError: Bookmarks are not exported in csv file.")
156-
elif urlinfo:
157-
output.print_bookmarks(database_connection.url_info(urlinfo))
158146
else:
159147
for url_to_add in insert:
160-
url = url_to_add
148+
url = url_to_add.strip() # Strip any leading/trailing whitespace
161149
try:
162150
validate_url = requests.get(url)
163151
validate_code = validate_url.status_code
164152
if validate_code == 200:
165153
is_url_added = database_connection.add_url(url)
166154
if is_url_added:
167-
print(f"\nSuccess: Bookmarked URL `{url}`.")
155+
print(f"\nSuccess: The URL '{url}' has been added to the database.")
168156
else:
169157
print("*" * 12, "\nInvalid URL\n", "*" * 11)
170158
if option_yes_no():
171159
is_url_added = database_connection.add_url(url)
172160
if is_url_added:
173-
print(f"\nSuccess: Bookmarked URL `{url}`.")
161+
print(f"\nSuccess: The URL '{url}' has been added to the database.")
174162

175163
except Exception:
176164
print("*" * 12, "\nInvalid URL\n", "*" * 11)
177165
if option_yes_no():
178166
is_url_added = database_connection.add_url(url)
179167
if is_url_added:
180-
print(f"\nSuccess: Bookmarked URL `{url}`.")
168+
print(f"\nSuccess: The URL '{url}' has been added to the database.")
181169

182170
def option_yes_no():
183171
"""

0 commit comments

Comments
 (0)