-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedium.py
More file actions
73 lines (58 loc) · 2.26 KB
/
Copy pathmedium.py
File metadata and controls
73 lines (58 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Main CLI entry point for a Medium API client
"""
import logging
import click
from dotenv import load_dotenv
from rich import print as rprint
from rich.console import Console
from rich.logging import RichHandler
from src.cli.commands.download import download
from src.medium_api_client.cache.disk_cache import DiskCache
from src.medium_api_client.client import MediumAPIClient
load_dotenv()
console = Console()
# Configure the root logger
logging.basicConfig(
level="INFO", # Set your desired logging level
format="%(message)s", # RichHandler handles its own formatting, but a simple format is needed
datefmt="[%X]", # Time format for RichHandler
handlers=[
RichHandler(
# console=console, # Pass your custom console if you created one
show_level=True,
show_time=True,
rich_tracebacks=True, # Enable rich tracebacks
tracebacks_theme="monokai", # Choose a traceback theme
tracebacks_word_wrap=True,
log_time_format="%Y-%m-%d %H:%M:%S", # Custom timestamp format
)
],
)
logger = logging.getLogger(__name__) # Get your module-specific logger
@click.group()
@click.option("--api-key", envvar="RAPIDAPI_KEY", help="RAPIDAPI_KEY environment variable")
@click.option("--cache-path", default="data/cache", help="Cache database path")
@click.option("--articles-path", default="data/articles", help="Saved articles path")
@click.option("--verbose", "-v", is_flag=True, help="Verbose output")
@click.pass_context
def cli(ctx, api_key, cache_path, articles_path, verbose):
"""Medium API CLI - Access Medium articles programmatically"""
if not api_key:
rprint("[red]Error: API key is required. Set RAPIDAPI_KEY environment variable or use --api-key option[/red]")
ctx.exit(1)
# Initialize cache
cache = DiskCache(db_path=cache_path)
# Create client
client = MediumAPIClient(api_key=api_key, cache=cache, logger=logger)
# Store in context for subcommands
ctx.ensure_object(dict)
ctx.obj["client"] = client
ctx.obj["console"] = console
ctx.obj["logger"] = logger
ctx.obj["articles_path"] = articles_path
ctx.obj["verbose"] = verbose
# Register commands
cli.add_command(download)
if __name__ == "__main__":
cli()