generated from ozdem1r/boilerplate_python_3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.py
51 lines (46 loc) · 1.94 KB
/
entrypoint.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
from booking_scraper.scraper import BookingScraper
from booking_scraper.model import HotelExtended
from booking_scraper.serializer import PydanticJSONEncoder
import json
import typer
from rich import print as pretty_print
import os
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
HTML_FILE_PATH = (
f"{PROJECT_ROOT}/data/Kempinski Hotel Bristol Berlin, Germany - Booking.com.html"
)
def init_scraper(
url: str = typer.Option(default=None, help="Hotel link to scrape from internet"),
local_file_path: str = typer.Option(
default=HTML_FILE_PATH, help="File path to scrape from local HTML file"
),
):
"""
Create an instance from BookingScraper class and scrape all hotel required hotel metadata
:param url: _description_, defaults to typer.Option( default=BASE_LINK, help="Hotel link to scrape from internet" )
:param local_file_path: _description_, defaults to typer.Option( default=None, help="File path to scrape from local HTML file" )
"""
booking_scraper = BookingScraper(
url=url,
local_file_path=local_file_path,
)
# mapping data with HotelExtended class
hotel_extended = HotelExtended(
hotel_name=booking_scraper.get_hotel_name(),
description=booking_scraper.get_description(),
number_of_reviews=booking_scraper.get_number_of_reviews(),
review_points=booking_scraper.get_review_points(),
address=booking_scraper.get_address(),
classification=booking_scraper.get_classification(), # re-check
room_categories=booking_scraper.get_room_categories(),
alternative_hotels=booking_scraper.get_alternative_hotels(),
)
hotel_extended_json = json.dumps(
hotel_extended.dict(), cls=PydanticJSONEncoder, indent=4
)
# rich print shows with better formatting
pretty_print(hotel_extended_json)
# comment print and use return
# return hotel_extended_json
if __name__ == "__main__":
typer.run(init_scraper)