Exemple #1
0
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}"
            )
Exemple #2
0
def import_last_bra():
    # Open data from meteo france via it's obscure rest api because they are not providing opendata for the current day
    # They start providing the BRA one day after it's been released, which makes the app useless.
    with connection_scope() as con:
        for dept in DepartmentTable.get(con):
            try:
                dept = get_bra_by_dept_from_mf_rpc_api(dept.d_number)
                for massif in dept:
                    xml = format_xml_from_mf_rpc(massif["corpsBulletin"])
                    processed_bra = process_xml(con, xml)
                    persist_bra(con, processed_bra)
            except HTTPError as e:
                log.critical(f"dept {dept.d_name} cannot be fetch no BRA")
                continue
            except Exception as e:
                log.critical(
                    f"an error occured when processing dept {dept.d_name} for today"
                )
Exemple #3
0
def import_last_bra():
    click.echo("This function doesn't work anymore sorry")
    sys.exit()
    # This is obsolete.
    db = create_database_connections().engine
    with connection_scope(db) as con:
        for dept in DepartmentTable.get(con):
            try:
                dept = get_bra_by_dept_from_mf_rpc_api(dept.d_number)
                for massif in dept:
                    xml = format_xml_from_mf_rpc(massif["corpsBulletin"])
                    processed_bra = process_xml(con, xml)
                    persist_bra(con, processed_bra)
            except HTTPError as e:
                log.critical(f"dept {dept['d_name']} cannot be fetch no BRA")
                log.debug(e)
                continue
            except Exception as e:
                log.critical(
                    f"an error occured when processing dept {dept['d_name']} for today"
                )
                log.debug(e)
Exemple #4
0
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}"
                )