Skip to content

Commit 408c9ff

Browse files
author
Adriano Sanges
committed
Add type annotations and improve import for scan_properties.py
- Update import for polars to use `import polars as pl` - Add explicit type hints for variables in the script - Improve type annotations for function return values and variables - Maintain consistent type annotation style across the script
1 parent b66be53 commit 408c9ff

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

real-estate-etl/scan_properties.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from bs4 import BeautifulSoup
2-
import polars
2+
import polars as pl
33
import duckdb
44
from scraper import parse_listing
55
from database import clean_properties, get_new_properties
@@ -14,30 +14,30 @@
1414

1515
load_dotenv()
1616

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")
2020

21-
data = parse_listing(url)
21+
data: list[dict] = parse_listing(url)
2222

23-
polars_df = polars.DataFrame(data)
23+
polars_df: pl.DataFrame = pl.DataFrame(data)
2424

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}")
2626

2727
con.sql("create table if not exists main.properties as select * from polars_df")
2828

2929
clean_properties(con)
3030

31-
new_properties = get_new_properties(con)
31+
new_properties: pl.DataFrame = get_new_properties(con)
3232
# 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)]
3434

3535
# Send messages in chunks of two
3636
for i in range(0, len(messages), 2):
3737
# Get the current chunk of two messages
38-
message_chunk = messages[i:i+2]
38+
message_chunk: list[str] = messages[i:i+2]
3939
# Join the two messages with a separator
40-
full_message = "\n\n".join(message_chunk)
40+
full_message: str = "\n\n".join(message_chunk)
4141
# Send the combined message
4242
send_message(full_message)
4343

0 commit comments

Comments
 (0)