-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (54 loc) · 1.44 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
import typer
from config.database import get_db
from scrapers import scrape_details, scrape_list
from services.item_service import ItemService
from utils.check_type import check_type
from utils.get_urls import get_urls
from utils.init_app import init_app
app = typer.Typer()
init_app()
session = next(get_db())
@app.command()
def list_scraper() -> None:
"""
Scrape list of items from URLs.
"""
urls = get_urls()
for k, v in urls.items():
_type = check_type(v)
scrape_list.scrape_list(session, _type, v)
@app.command()
def list_scraper_url(
url: str
) -> None:
"""
Scrape list of items from a single URL.
Args:
url (str): URL to scrape.
"""
_type = check_type(url)
scrape_list.scrape_list(session, _type, url)
@app.command()
def details_scraper() -> None:
"""
Scrape details for all items.
"""
items = ItemService(next(get_db())).get_all_details_not_found()
for item in items:
scrape_details.scrape_details(session, item.url)
@app.command()
def export_to_json(
start_page: int = typer.Option(1, min=1),
page_limit: int = typer.Option(50, min=1)
) -> None:
"""
Export items to JSON files.
Args:
start_page (int): Start page number.
page_limit (int): Number of items per page.
Returns:
None
"""
ItemService(session).export_to_json(start_page, page_limit)
if __name__ == "__main__":
app()