def store_scraper_success(scraper_success: ScraperSuccessModel, jurisdiction_id: str) -> bool: """Store a scraper success event""" jurisdiction_id = validate_jid(jurisdiction_id) ss = ScraperSuccessEntry( jid=jurisdiction_id, date=scraper_success.date, ) session = SessionFactory.for_schema_base( schema_base_for_system_level(SystemLevel.COUNTY)) session.add(ss) session.commit() return True
def store_scraper_success(scraper_success: ScraperSuccessModel, jurisdiction_id: str) -> bool: """Store a scraper success event""" jurisdiction_id = validate_jid(jurisdiction_id) ss = ScraperSuccessEntry( jid=jurisdiction_id, date=scraper_success.date, ) with SessionFactory.using_database( SQLAlchemyDatabaseKey.for_schema( SystemLevel.COUNTY.schema_type())) as session: session.add(ss) return True
def store_single_count(sc: SingleCount, jurisdiction_id: str): """Store a single count""" jurisdiction_id = validate_jid(jurisdiction_id) sca = SingleCountAggregate( jid=jurisdiction_id, ethnicity=sc.ethnicity.value if sc.ethnicity else None, gender=sc.gender.value if sc.gender else None, race=sc.race.value if sc.race else None, count=sc.count, date=sc.date, ) session = SessionFactory.for_schema_base( schema_base_for_system_level(SystemLevel.COUNTY)) session.add(sca) session.commit() return True
def store_single_count(sc: SingleCount, jurisdiction_id: str) -> bool: """Store a single count""" jurisdiction_id = validate_jid(jurisdiction_id) sca = SingleCountAggregate( jid=jurisdiction_id, ethnicity=sc.ethnicity.value if sc.ethnicity else None, gender=sc.gender.value if sc.gender else None, race=sc.race.value if sc.race else None, count=sc.count, date=sc.date, ) logging.info("Writing single count to the database: %s", to_string(sc)) if not should_persist(): return True session = SessionFactory.for_schema_base( schema_base_for_system_level(SystemLevel.COUNTY)) session.add(sca) session.commit() return True
def store_single_count(sc: SingleCount, jurisdiction_id: str) -> bool: """Store a single count""" jurisdiction_id = validate_jid(jurisdiction_id) sca = SingleCountAggregate( jid=jurisdiction_id, ethnicity=sc.ethnicity.value if sc.ethnicity else None, gender=sc.gender.value if sc.gender else None, race=sc.race.value if sc.race else None, count=sc.count, date=sc.date, ) logging.info("Writing single count to the database: %s", to_string(sc)) if not should_persist(): return True with SessionFactory.using_database( SQLAlchemyDatabaseKey.for_schema( SystemLevel.COUNTY.schema_type())) as session: session.add(sca) return True