|
1 | 1 | from bs4 import BeautifulSoup |
2 | | -import polars |
| 2 | +import polars as pl |
3 | 3 | import duckdb |
4 | 4 | from scraper import parse_listing |
5 | 5 | from database import clean_properties, get_new_properties |
|
14 | 14 |
|
15 | 15 | load_dotenv() |
16 | 16 |
|
17 | | - url = os.getenv("scrape_url") |
18 | | - warehouse_name = os.getenv("warehouse_name") |
19 | | - motherduck_token = os.getenv("motherduck_token") |
| 17 | + url: str = os.getenv("scrape_url") |
| 18 | + warehouse_name: str = os.getenv("warehouse_name") |
| 19 | + motherduck_token: str = os.getenv("motherduck_token") |
20 | 20 |
|
21 | | - data = parse_listing(url) |
| 21 | + data: list[dict] = parse_listing(url) |
22 | 22 |
|
23 | | - polars_df = polars.DataFrame(data) |
| 23 | + polars_df: pl.DataFrame = pl.DataFrame(data) |
24 | 24 |
|
25 | | - con = duckdb.connect(f"md:{warehouse_name}?motherduck_token={motherduck_token}") |
| 25 | + con: duckdb.DuckDBPyConnection = duckdb.connect(f"md:{warehouse_name}?motherduck_token={motherduck_token}") |
26 | 26 |
|
27 | 27 | con.sql("create table if not exists main.properties as select * from polars_df") |
28 | 28 |
|
29 | 29 | clean_properties(con) |
30 | 30 |
|
31 | | - new_properties = get_new_properties(con) |
| 31 | + new_properties: pl.DataFrame = get_new_properties(con) |
32 | 32 | # Iterate over the DataFrame and format each property |
33 | | - messages = [format_property_message(row) for row in new_properties.iter_rows(named=True)] |
| 33 | + messages: list[str] = [format_property_message(row) for row in new_properties.iter_rows(named=True)] |
34 | 34 |
|
35 | 35 | # Send messages in chunks of two |
36 | 36 | for i in range(0, len(messages), 2): |
37 | 37 | # Get the current chunk of two messages |
38 | | - message_chunk = messages[i:i+2] |
| 38 | + message_chunk: list[str] = messages[i:i+2] |
39 | 39 | # Join the two messages with a separator |
40 | | - full_message = "\n\n".join(message_chunk) |
| 40 | + full_message: str = "\n\n".join(message_chunk) |
41 | 41 | # Send the combined message |
42 | 42 | send_message(full_message) |
43 | 43 |
|
|
0 commit comments