def try_to_parse(start: str, end: str, tries: int, scraper: scrapers.FakeScraper) -> str: """ Parses filings and settings between start and end dates. Tries `tries` times before giving up. If all attempts fail, returns the start and end date, otherwise returns 'success'. """ for attempt in range(1, tries + 1): try: parse_filings.parse_filings_on_cloud(afterdate=start, beforedate=end, get_old_active=False, scraper=scraper) parse_settings.parse_settings_on_cloud(afterdate=start, beforedate=end, write_to_sheets=False, scraper=scraper) logger.info(Fore.GREEN + "Successfully parsed filings and settings " + f"between {start} and {end} on attempt {attempt}.\n" + Style.RESET_ALL) return "success" except Exception as error: if attempt == tries: logger.error(f"Error message: {error}") message = f"{start}, {end}" logger.error(Fore.RED + f"Failed to parse filings and settings between {start} " + f"and {end} on all {tries} attempts.\n" + Style.RESET_ALL) return message
def try_to_parse(start, end, tries): for attempt in range(1, tries + 1): try: parse_filings_on_cloud(start, end, get_old_active=False) parse_settings_on_cloud(start, end) logger.info( Fore.GREEN + f"Successfully parsed filings between {start} and {end} on attempt {attempt}.\n" + Style.RESET_ALL) return "success" except Exception as error: if attempt == tries: logger.error(f"Error message: {error}") message = f"{start}, {end}" logger.error( Fore.RED + f"Failed to parse filings and settings between {start} and {end} on all {tries} attempts.\n" + Style.RESET_ALL) return message
def scrape_filings(): """Scrapes all case filings data from the past week and outputs results to PostgreSQL database""" seven_days_ago = get_date_from_today("-", 7, "past") parse_filings.parse_filings_on_cloud(seven_days_ago, date.today().strftime(f"%-m-%-d-%Y"))
def scrape_filings(): seven_days_ago = get_date_from_today("-", 7, "past") parse_filings_on_cloud(seven_days_ago, date.today().strftime(f"%-m-%-d-%Y"))