Add nice colors
This commit is contained in:
parent
e8e5e87c07
commit
edd6cf679f
1 changed files with 15 additions and 15 deletions
30
app/cli.py
30
app/cli.py
|
|
@ -6,9 +6,9 @@ from datetime import datetime, timedelta
|
|||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import click
|
||||
import typer
|
||||
from reader import Feed, ParseError, Reader, StorageError, UpdatedFeed, UpdateError, UpdateResult
|
||||
from rich import print
|
||||
|
||||
from app.dependencies import get_reader
|
||||
from app.scrapers.rss_link_database import scrape
|
||||
|
|
@ -25,7 +25,7 @@ app = typer.Typer(
|
|||
def _add_broken_feed_to_csv(feed: Feed | UpdateResult | None) -> None:
|
||||
"""Add a broken feed to a CSV file."""
|
||||
if feed is None:
|
||||
click.echo("Feed is None.", err=True)
|
||||
print("Feed is None.")
|
||||
return
|
||||
|
||||
with Path("broken_feeds.csv").open("a", encoding="utf-8") as f:
|
||||
|
|
@ -39,7 +39,7 @@ def _add_broken_feed_to_csv(feed: Feed | UpdateResult | None) -> None:
|
|||
def update_feeds() -> None:
|
||||
"""Update all the feeds."""
|
||||
reader: Reader = get_reader()
|
||||
click.echo("Updating feeds...")
|
||||
print("Updating feeds...")
|
||||
|
||||
all_feeds: Iterable[Feed] = reader.get_feeds(updates_enabled=True, broken=False)
|
||||
feeds: list[Feed] = []
|
||||
|
|
@ -56,36 +56,36 @@ def update_feeds() -> None:
|
|||
else:
|
||||
feeds.append(feed)
|
||||
|
||||
click.echo(f"Feeds to update: {len(feeds)}")
|
||||
print(f"Feeds to update: {len(feeds)}")
|
||||
|
||||
for feed in feeds:
|
||||
try:
|
||||
updated_feed: UpdatedFeed | None = reader.update_feed(feed)
|
||||
click.echo(f"Updated feed: {feed.url}")
|
||||
print(f"Updated feed: {feed.url}")
|
||||
if updated_feed is not None:
|
||||
click.echo(
|
||||
f"New: {updated_feed.new}, modified: {updated_feed.modified}, unmodified: {updated_feed.unmodified}", # noqa: E501
|
||||
print(
|
||||
f"New: [green]{updated_feed.new}[/green], modified: [yellow]{updated_feed.modified}[/yellow], unmodified: {updated_feed.unmodified}", # noqa: E501
|
||||
)
|
||||
|
||||
except ParseError as e:
|
||||
# An error occurred while retrieving/parsing the feed.
|
||||
click.echo(f"Error parsing feed: {feed.url} ({e})", err=True)
|
||||
print(f"[bold red]Error parsing feed[/bold red]: {feed.url} ({e})")
|
||||
except UpdateError as e:
|
||||
# An error occurred while updating the feed.
|
||||
# Parent of all update-related exceptions.
|
||||
click.echo(f"Error updating feed: {feed.url} ({e})", err=True)
|
||||
print(f"[bold red]Error updating feed[/bold red]: {feed.url} ({e})")
|
||||
except StorageError as e:
|
||||
# An exception was raised by the underlying storage.
|
||||
click.echo(f"Error updating feed: {feed.url}", err=True)
|
||||
click.echo(f"Storage error: {e}", err=True)
|
||||
print(f"[bold red]Error updating feed[/bold red]: {feed.url}")
|
||||
print(f"[bold red]Storage error[/bold red]: {e}")
|
||||
except AssertionError:
|
||||
# An assertion failed.
|
||||
click.echo(f"Assertion error: {feed.url}", err=True)
|
||||
print(f"[bold red]Assertion error[/bold red]: {feed.url}")
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
reader.disable_feed_updates(feed)
|
||||
_add_broken_feed_to_csv(feed)
|
||||
|
||||
click.echo("Feeds updated.")
|
||||
print("Feeds updated.")
|
||||
|
||||
|
||||
@app.command(
|
||||
|
|
@ -94,9 +94,9 @@ def update_feeds() -> None:
|
|||
)
|
||||
def grab_links() -> None:
|
||||
"""Grab RSS feeds from different sources."""
|
||||
click.echo("Grabbing links...")
|
||||
print("Grabbing links...")
|
||||
rss_links: str = scrape()
|
||||
click.echo(rss_links)
|
||||
print(rss_links)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue