def import_all_bra(): """ Same as `import_bra` but we request from March 2016 to now. """ start_date = date(year=2016, month=3, day=10) date_range = [ date.today() - timedelta(days=x) for x in range(0, (date.today() - start_date).days + 1) ] for d in date_range: massif = "" try: bra_dates = get_bra_date(d) with connection_scope() as con: for massif, m_date in bra_dates.items(): if not check_bra_record_exist(con, massif, m_date): xml = get_bra_xml(massif, m_date) processed_bra = process_xml(con, xml) persist_bra(con, processed_bra) click.echo(f"Persist {massif.capitalize()}") except Exception as e: log.debug(e) log.critical( f"an error occured when processing massif {massif} for date {d}" )
def test_empty_db(self, database): """ an empty db should return false """ with connection_scope(database.engine) as con: r = check_bra_record_exist(con, "CHABLAIS", datetime.now()) assert r is False
def import_bra(bra_date): """ * setup * request https://donneespubliques.meteofrance.fr/donnees_libres/Pdf/BRA/bra.%Y%m%d.json with all the date from december 2016 to today * if not 302 (302 means 404 at meteofrance ðŸ˜) * for all the date in all the json, download the xml of bra * process (download + post process) * import """ bra_dates = get_bra_date(bra_date) with connection_scope() as con: for massif, m_date in bra_dates.items(): try: if not check_bra_record_exist(con, massif, m_date): xml = get_bra_xml(massif, m_date) processed_bra = process_xml(con, xml) persist_bra(con, processed_bra) click.echo(f"Persist {massif.capitalize()}") except Exception as e: log.debug(e) log.critical( f"an error occured when processing massif {massif} for date {m_date}" )
def test_already_exist_record(self, database): with connection_scope(database.engine) as con: self.load_data(con, datetime.now()) r = check_bra_record_exist(con, "test", datetime.now()) assert r is True