forked from open-austin/eviction-hearing-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_all_filings_settings_between_dates.py
47 lines (36 loc) · 1.7 KB
/
get_all_filings_settings_between_dates.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
"""Script to get all filings and settings between two dates. To use: python get_all_filings_settings_between_dates.py mm-dd-yyy mm-dd-yyyy"""
import logging
import click
import sys
from colorama import Fore, Style
from get_all_filings_settings_since_date import split_into_weeks, try_to_parse
from emailing import send_email
logger = logging.getLogger()
logging.basicConfig(stream=sys.stdout)
logger.setLevel(logging.INFO)
#
# date should be string in format (m)m-(d)d-yyyy
def get_all_filings_settings_between_dates(start_date: str, end_date: str):
"""Gets all filings and settings between `start_date` and `end_date` but splits it up by week. Logs the weeks that failed."""
weeks = split_into_weeks(start_date, end_date)
logger.info(f"Will get all filings and settings between {start_date} and {end_date}\n")
failures = []
for week_start, week_end in weeks:
msg = try_to_parse(week_start, week_end, 5)
if msg != "success":
failures.append(msg)
if failures:
failures_str = "\n".join(failures)
logger.info("All failures:")
logger.info(Fore.RED + failures_str + Style.RESET_ALL)
send_email(failures_str, "Date ranges for which parsing filings and settings failed")
else:
logger.info(Fore.GREEN + f"There were no failures when getting all filings between {start_date} and {end_date} - yay!!" + Style.RESET_ALL)
if __name__ == "__main__":
@click.command()
@click.argument("start_date", nargs=1)
@click.argument("end_date", nargs=1)
# dates should be in format (m)m-(d)d-yyyy
def get_all_between_dates(start_date, end_date):
get_all_filings_settings_between_dates(start_date, end_date)
get_all_between_dates()