Skip to content

Commit

Permalink
Merge pull request #172 from pythonpune/formatcode
Browse files Browse the repository at this point in the history
Formatting code with pre-commit configurations settings
  • Loading branch information
ganeshhubale authored Oct 18, 2024
2 parents 44c3e28 + de8ef0f commit ab22502
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 96 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Pre-Commit and Cross-Platform Test Suite

on:
pull_request:
pull_request:
branches:
- master
types:
Expand All @@ -12,7 +12,7 @@ on:
# Run every Friday at 23:59 UTC
- cron: '59 23 * * 5'
workflow_dispatch:

jobs:
pre-commit:
name: Pre-Commit Checks
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
name: Reorder Python Imports
language_version: python3
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.12.0
hooks:
- id: black
name: Formate with Black
Expand Down
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@
master_doc = "index"

# General information about the project.
project = u"readit"
copyright = u"2018, projectreadit organization"
author = u"projectreadit organization"
project = "readit"
copyright = "2018, projectreadit organization"
author = "projectreadit organization"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u""
version = ""
# The full version, including alpha/beta/rc tags.
release = u"v0.2"
release = "v0.2"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -145,15 +145,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "readit.tex", u"readit Documentation", u"projectreadit organization", "manual"),
(master_doc, "readit.tex", "readit Documentation", "projectreadit organization", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "readit", u"readit Documentation", [author], 1)]
man_pages = [(master_doc, "readit", "readit Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -165,7 +165,7 @@
(
master_doc,
"readit",
u"readit Documentation",
"readit Documentation",
author,
"readit",
"One line description of project.",
Expand Down
83 changes: 64 additions & 19 deletions readit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,27 @@
@click.option("--tag", "-t", help="Use to tag url --> readit -a <url1> -t <tag1>")
@click.option("--delete", "-d", help="Remove a URL of particular ID --> readit -d <url_id>")
@click.option("--clear", "-c", nargs=0, help="Clear bookmarks --> readit -c")
@click.option("--update", "-u", help="Update a URL for specific ID --> readit -u <existing_id> <new_url>")
@click.option("--search", "-s", help="Search for bookmarks using either a tag or a substring of the URL --> readit -s <tag> or <substring>")
@click.option(
"--update", "-u", help="Update a URL for specific ID --> readit -u <existing_id> <new_url>"
)
@click.option(
"--search",
"-s",
help="""
Search for bookmarks using either a tag or a substring of the URL
--> readit -s <tag> or <substring>
""",
)
@click.option("--view", "-v", multiple=True, nargs=0, help="Show bookmarks --> readit -v")
@click.option("--openurl", "-o", help="Open a URL in your browser by entering a part of the URL. --> readit -o <url_substring>")
@click.option(
"--openurl",
"-o",
help="Open a URL in your browser by entering a part of the URL. --> readit -o <url_substring>",
)
@click.option("--version", "-V", is_flag=True, help="Check latest version --> readit -V")
@click.option("--export", "-e", multiple=True, nargs=0, help="Export URLs in csv file --> readit -e")
@click.option(
"--export", "-e", multiple=True, nargs=0, help="Export URLs in csv file --> readit -e"
)
@click.option("--taglist", "-tl", multiple=True, nargs=0, help="Show all Tags --> readit -tl")
@click.argument("insert", nargs=-1, required=False)
def main(
Expand All @@ -61,7 +76,10 @@ def main(
if not tag:
tag = "general" # Default tag if none provided
if not url:
print("\033[91m\nError: URL not provided. Please use the following format: readit -a <url> -t <tag>\033[0m")
print(
"""\033[91m\nError: URL not provided. Please use the following format:
readit -a <url> -t <tag>\033[0m"""
)
sys.exit(0)
try:
validate_code = check_url_validation(url)
Expand All @@ -71,19 +89,25 @@ def main(
if is_url_added:
print(f"\033[92m\nSuccess! Bookmarked URL `{url}` with tag `{tag}`. πŸŽ‰\033[0m")
else:
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
print(
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
) # Warning in yellow
if option_yes_no():
is_url_added = database_connection.tag_url(url, tag)
if is_url_added:
print(f"\033[92m\nSuccess! Bookmarked URL `{url}` with tag `{tag}`. πŸŽ‰\033[0m")
print(
f"\033[92m\nSuccess! Bookmarked URL `{url}` with tag `{tag}`. πŸŽ‰\033[0m"
)
except Exception:
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
print(
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
) # Warning in yellow
if option_yes_no():
is_url_added = database_connection.tag_url(url, tag)
if is_url_added:
print(f"\033[92m\nSuccess! Bookmarked URL `{url}` with tag `{tag}`. πŸŽ‰\033[0m")
elif delete:
database_connection.delete_url(delete)
database_connection.delete_url(delete)
elif update:
url_list = []
for update_to_url in update:
Expand All @@ -96,11 +120,15 @@ def main(
if validate_code == 200:
database_connection.update_url(url_id, url)
else:
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
print(
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
) # Warning in yellow
if option_yes_no():
database_connection.update_url(url_id, url)
except Exception:
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
print(
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
) # Warning in yellow
if option_yes_no():
is_url_updated = database_connection.update_url(url_id, url)
if is_url_updated:
Expand Down Expand Up @@ -131,19 +159,35 @@ def main(
if validate_code == 200:
is_url_added = database_connection.add_url(url)
if is_url_added:
print(f"\033[92mSuccess! The URL '{url}' has been successfully bookmarked. πŸŽ‰\033[0m")
print(
f"""
\033[92mSuccess! The URL '{url}'
has been successfully bookmarked. πŸŽ‰\033[0m
"""
)
else:
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
print(
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
) # Warning in yellow
if option_yes_no():
is_url_added = database_connection.add_url(url)
if is_url_added:
print(f"\033[92mSuccess! The URL '{url}' has been successfully bookmarked. πŸŽ‰\033[0m")
print(
f"""\033[92mSuccess! The URL '{url}'
has been successfully bookmarked. πŸŽ‰\033[0m"""
)
except Exception:
print("\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m") # Warning in yellow
print(
"\033[93m\nWarning: The URL seems to be inaccessible at the moment.\033[0m"
) # Warning in yellow
if option_yes_no():
is_url_added = database_connection.add_url(url)
if is_url_added:
print(f"\033[92mSuccess! The URL '{url}' has been successfully bookmarked. πŸŽ‰\033[0m")
print(
f"""\033[92mSuccess! The URL '{url}'
has been successfully bookmarked. πŸŽ‰\033[0m"""
)


def option_yes_no():
"""
Expand All @@ -155,12 +199,13 @@ def option_yes_no():
else:
sys.exit(0)


def check_url_validation(url_given):
url = url_given.strip() # Strip any leading/trailing whitespace
if not url:
print("\033[91m\nError: Cannot add an empty URL.\033[0m")
sys.exit(0)

# Initialize the validation code
validate_code = 0

Expand All @@ -174,9 +219,9 @@ def check_url_validation(url_given):
url = full_url # Update URL with valid prefix
break
else:
validate_code = 0
validate_code = 0
else:
# If URL starts with http or https, validate directly
response = requests.get(url)
validate_code = response.status_code
return validate_code
return validate_code
Loading

0 comments on commit ab22502

Please sign in to comment.