-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
71 lines (61 loc) · 1.83 KB
/
main.py
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
import click
from typing import Callable
from dataclasses import dataclass
from scraper.product_urls import collect_product_urls
from scraper.product_details import extract_product_details
from scraper.reviews import collect_reviews
@dataclass
class MenuItem:
id: int
title: str
description: str
handler: Callable
class ScraperTool:
def __init__(self):
self.menu_items = [
MenuItem(
1,
"Product URL Collector",
"Extract and save product URLs for a specific category",
collect_product_urls
),
MenuItem(
2,
"Product Details Extractor",
"Gather and save detailed product information",
extract_product_details
),
MenuItem(
3,
"Review Collector",
"Download and save product reviews",
collect_reviews
)
]
@click.group()
def cli():
pass
@cli.command()
def menu():
tool = ScraperTool()
while True:
click.clear()
click.secho("=== Web Scraper Tool ===", fg="blue", bold=True)
click.echo()
for item in tool.menu_items:
click.secho(f"{item.id}. {item.title}", fg="green")
click.echo(f" {item.description}")
click.echo()
click.echo("0. Exit")
click.echo()
choice = click.prompt("Select an option", type=int, default=0)
if choice == 0:
click.echo("Exiting...")
break
if 1 <= choice <= len(tool.menu_items):
tool.menu_items[choice-1].handler()
else:
click.secho("Invalid option!", fg="red")
click.pause()
if __name__ == "__main__":
cli()