-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_candidates.py
39 lines (32 loc) · 1.52 KB
/
upload_candidates.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
"""Upload MLS listing candidates to dropbox."""
from pathlib import Path
import pandas as pd
from wheretolive.dropbox_uploader import dropbox_save
from wheretolive.logconf import get_logger
from wheretolive.postgis import PostGIS
logger = get_logger(__name__)
def upload_candidate(requestor_name: str):
"""Upload candidate results for a specific person."""
sql = f"SELECT * FROM {requestor_name}_candidates;"
df = pd.read_sql(
sql, PostGIS().connection, parse_dates=["mls_insert_dt", "price_change_dt"]
)
logger.info(f"Extracted candidates for {requestor_name}")
dump_path = Path(__file__).resolve().parent
full_file = dump_path / f"{requestor_name}_mls_candidates.html"
df.to_html(full_file, render_links=True)
df["date_filter"] = df[["mls_insert_dt", "price_change_dt"]].max(axis="columns")
new_mask = df["date_filter"] == df["date_filter"].max()
new_file = dump_path / f"{requestor_name}_rfaster_candidates_newest.html"
df.loc[new_mask].drop(columns="date_filter").to_html(new_file, render_links=True)
logger.info("Saved candidates to local html.")
dropbox_full_path = f"/wheretolive/{requestor_name}/mls_full.html"
dropbox_new_path = f"/wheretolive/{requestor_name}/mls_new.html"
dropbox_save(full_file, dropbox_full_path)
dropbox_save(new_file, dropbox_new_path)
logger.info("Uploaded candidates to dropbox.")
full_file.unlink()
new_file.unlink()
logger.info("Deleted locally saved extracts.")
if __name__ == "__main__":
upload_candidate("ian")