def create_service_demarches(row, place: Place): print("in service: demarches") service_demarches = Service() service_demarches.place_id = place.id service_demarches.name = "Accompagnement aux démarches administratives en ligne" service_demarches.description = row["Type démarches"] service_demarches.support_access = utilities.process_support_access( row["Conditions accès démarches"] ) service_demarches.support_mode = utilities.process_support_mode( row["Accompagnement démarches"] ) service_demarches.is_free = utilities.process_price(row["Coût accès démarches"]) service_demarches.schedule_hours_raw = row["Horaires démarches"] service_demarches.schedule_hours_osm_format = utilities.process_opening_hours_to_osm_format( service_demarches.schedule_hours_raw ) service_demarches.additional_information = { "demarches_specifiques": row["Démarches spécifiques"], "frequence_demarches": row["Fréquence démarches"], } service_demarches.save() print( row["ID Exporter les données"], "-->", place.id, service_demarches.id, )
def create_service_mednum(row, place: Place): print("in service: mednum") service_mednum = Service() service_mednum.place_id = place.id service_mednum.name = "Acquisition de compétences numériques" service_mednum.description = row["Compétences médnum"] service_mednum.support_access = utilities.process_support_access( row["Conditions accès médnum"] ) service_mednum.support_mode = utilities.process_support_mode( row["Accompagnement médnum"] ) service_mednum.is_free = utilities.process_price(row["Coût accès démarches"]) service_mednum.price_details = row["Coût accès démarches"] service_mednum.schedule_hours_raw = row["Horaires médnum"] service_mednum.schedule_hours_osm_format = utilities.process_opening_hours_to_osm_format( service_mednum.schedule_hours_raw ) service_mednum.additional_information = { "support_access_raw": row["Conditions accès médnum"], "support_mode_raw": row["Accompagnement médnum"], "frequence_mednum": row["Fréquence médnum"], } service_mednum.save() print( row["ID Exporter les données"], "-->", place.id, service_mednum.id, )
def process_place_opening_hours(place_output_dict, place_input_dict, input_field): """ - Exemple avec 1 champ : - input_field = "horaires" - horaires_ouverture_brut = "du lundi au vendredi de 9h à 18h" - Exemple avec plusieurs champs : - input_field = "lundi,mardi" - input_field_to_list = ["lundi", "mardi"] - place_field_to_list = ["Lundi: 9h-18h", "Mardi: 9h-12h"] - horaires_ouverture_brut = "Lundi: 9h-18h, Mardi: 9h-12h" """ OPENSTREETMAP_DAY_SEPERATOR = "; " # set horaires_ouverture_brut if DEFAULT_SEPARATEUR_CHAMPS_MULTIPLES in input_field: input_field_to_list = input_field.split( DEFAULT_SEPARATEUR_CHAMPS_MULTIPLES) place_field_to_list = [ place_input_dict[item] for item in input_field_to_list ] place_output_dict[ "horaires_ouverture_brut"] = OPENSTREETMAP_DAY_SEPERATOR.join( place_field_to_list) # avoid empty "; ; ; " value if re.match("^[ ;]*$", place_output_dict["horaires_ouverture_brut"]): place_output_dict["horaires_ouverture_brut"] = "" else: place_output_dict["horaires_ouverture_brut"] = ( place_input_dict[input_field] if input_field else "") # set horaires_ouverture_osm if place_output_dict["horaires_ouverture_brut"]: place_output_dict[ "horaires_ouverture_osm"] = utilities.process_opening_hours_to_osm_format( place_output_dict["horaires_ouverture_brut"]) return place_output_dict
def create_service_equipement(row, place: Place): print("in service: acces équipement") service_equipement = Service() service_equipement.place_id = place.id service_equipement.name = "Accès à un équipement informatique" service_equipement.description = row["Type équipement"] service_equipement.support_access = utilities.process_support_access( row["Conditions accès équipement"] ) service_equipement.is_free = utilities.process_price(row["Coût accès équipement"]) service_equipement.price_details = row["Coût accès équipement"] service_equipement.schedule_hours_raw = row["Horaires équipement"] service_equipement.schedule_hours_osm_format = utilities.process_opening_hours_to_osm_format( service_equipement.schedule_hours_raw ) service_equipement.additional_information = { "support_access_raw": row["Conditions accès équipement"], } service_equipement.save() print( row["ID Exporter les données"], "-->", place.id, service_equipement.id, )
def create_place(row, data_set): print("in place") place_dict = {} """ place_fields_set """ for elem in data_set.import_config.get("place_fields_set", []): if "type" in elem: if elem["type"] == "boolean": place_dict[elem["place_field"]] = bool(elem["value"] == "true") else: place_dict[elem["place_field"]] = elem["value"] """ place_fields_mapping_auto """ for elem in data_set.import_config.get("place_fields_mapping_auto", []): place_dict[elem["place_field"]] = row[elem["file_field"]] """ place_fields_mapping_boolean """ for elem in data_set.import_config.get("place_fields_mapping_boolean", []): place_dict[elem["place_field"]] = utilities.process_boolean( row[elem["file_field"]]) """ place_fields_mapping_process - type - status - legal_entity_type - target_audience_raw - support_access_raw - support_mode_raw - contact_phone_raw - price_details - labels_raw - address_raw - opening_hours_raw """ for elem in data_set.import_config.get("place_fields_mapping_process", []): if elem["place_field"] == "type": place_dict["type"] = utilities.process_type( row[elem["file_field"]]) if elem["place_field"] == "status": place_dict["status"] = utilities.process_status( row[elem["file_field"]]) if elem["place_field"] == "legal_entity_type": place_dict[ "legal_entity_type"] = utilities.process_legal_entity_type( row[elem["file_field"]]) if elem["place_field"] == "target_audience_raw": place_dict["target_audience_raw"] = row[elem["file_field"]] place_dict["target_audience"] = utilities.process_target_audience( place_dict["target_audience_raw"]) if elem["place_field"] == "support_access_raw": place_dict["support_access_raw"] = row[elem["file_field"]] place_dict["support_access"] = utilities.process_support_access( place_dict["support_access_raw"]) if elem["place_field"] == "support_mode_raw": place_dict["support_mode_raw"] = row[elem["file_field"]] place_dict["support_mode"] = utilities.process_support_mode( place_dict["support_mode_raw"]) if elem["place_field"] == "labels_raw": place_dict["labels_raw"] = row[elem["file_field"]] place_dict["labels"] = utilities.process_labels( place_dict["labels_raw"]) if elem["place_field"] == "contact_phone_raw": place_dict["contact_phone_raw"] = row[elem["file_field"]] place_dict["contact_phone"] = utilities.process_phone_number( place_dict["contact_phone_raw"]) if elem["place_field"] == "price_details": place_dict["price_details"] = row[elem["file_field"]] place_dict["is_free"] = utilities.process_price( place_dict["price_details"]) if elem["place_field"] == "address_raw": """ Different options: - "20 Avenue de Ségur 75007 Paris" - ["20 Avenue de Ségur", "75007", "Paris"] - [["20", "Avenue", "de Ségur"], "75007", "Paris"] - "" """ if type(elem["file_field"]) == list: address_temp = "" if type(elem["file_field"][0]) == list: address_temp = " ".join([ row[item].strip() for item in elem["file_field"][0] if item not in ["", "0", 0, False, None] ]) else: address_temp = row[elem["file_field"][0]] place_dict["address_raw"] = utilities.clean_address_raw_list( address=address_temp, postcode=row[elem["file_field"][1]], city=row[elem["file_field"][2]], ) else: place_dict["address_raw"] = row[elem["file_field"]] address_api_results_processed = utilities.process_address( place_dict["address_raw"]) if address_api_results_processed: place_dict[ "address_housenumber"] = address_api_results_processed[ "housenumber"] place_dict["address_street"] = address_api_results_processed[ "street"] place_dict["address_postcode"] = address_api_results_processed[ "postcode"] place_dict["address_citycode"] = address_api_results_processed[ "citycode"] place_dict["address_city"] = address_api_results_processed[ "city"] place_dict[ "address_departement_code"] = address_api_results_processed[ "departement_code"] place_dict[ "address_departement_name"] = address_api_results_processed[ "departement_name"] place_dict[ "address_region_name"] = address_api_results_processed[ "region_name"] place_dict["latitude"] = address_api_results_processed[ "latitude"] place_dict["longitude"] = address_api_results_processed[ "longitude"] if elem["place_field"] == "opening_hours_raw": """ Different options: - "du lundi au vendredi de 9h à 18h" - ["Lundi: 9h-18h", "Mardi: 9h-12h"] - "" """ if type(elem["file_field"]) == list: place_dict["opening_hours_raw"] = [ row[item] for item in elem["file_field"] ] else: place_dict["opening_hours_raw"] = row[elem["file_field"]] place_dict[ "opening_hours_osm_format"] = utilities.process_opening_hours_to_osm_format( place_dict["opening_hours_raw"]) """ additional_information """ place_dict["additional_information"] = {} for elem in data_set.import_config.get( "place_fields_mapping_additional_information", []): if type(elem) == dict: # elem["place_field"] place_dict["additional_information"][elem["file_field"]] = row[ elem["file_field"]] if type(elem) == str: place_dict["additional_information"][elem] = row[elem] place_dict["data_set_id"] = data_set.id print(place_dict) place = Place.objects.create(**place_dict) # print(row["ID"], "-->", place.id) print("-->", place.id) return place
def create_place(row, source_id): print("in place") place = Place() place.name = row["Nom SP"] type_value = utilities.find_verbose_choice( constants.PLACE_TYPE_CHOICES, row["Nature"] ) if type_value: place.type = type_value status_value = utilities.find_verbose_choice( constants.PLACE_STATUS_CHOICES, row["Statut"] ) if status_value: place.status = status_value place.address_raw = utilities.clean_address_raw_list( row["Adresse SP"], row["CP"], row["Commune"] ) address_api_results_processed = utilities.process_address(place.address_raw) if address_api_results_processed: place.address_housenumber = address_api_results_processed["housenumber"] place.address_street = address_api_results_processed["street"] place.address_postcode = address_api_results_processed["postcode"] place.address_citycode = address_api_results_processed["citycode"] place.address_city = address_api_results_processed["city"] place.address_departement_code = address_api_results_processed[ "departement_code" ] place.address_departement_name = address_api_results_processed[ "departement_name" ] place.address_region_name = address_api_results_processed["region_name"] place.latitude = utilities.process_float(row["Latitude"]) place.longitude = utilities.process_float(row["Longitude"]) place.contact_phone_raw = row["Tél SP"] place.contact_phone = utilities.process_phone_number(row["Tél SP"]) place.contact_email = row["Mail SP"] place.contact_website_url = row["Site SP"] place.opening_hours_raw = row["Ouverture"] place.opening_hours_osm_format = utilities.process_opening_hours_to_osm_format( place.opening_hours_raw ) place.target_audience_raw = row["Publics"] place.target_audience = utilities.process_target_audience(place.target_audience_raw) place.additional_information = { "id": row["ID Exporter les données"], "epn": row["EPN"], "horodateur": row["Horodateur"], "public_specifique": row["Publics spécifiques"], "connaissance_aptic": row["connaissance aptic"], "interessee_aptic": row["intéréssée aptic"], "pmr": row["PMR"], "transports_en_commun": row["Transports en commun"], "collaboration": row["Collaboration"], "autres_structures_partenaires": row["Autres structures partenaires"], "autres_offres": row["Autres offres"], "cheques_aptic": row["chéques APTIC"], "lien_picto_access": row["LIEN PICTO ACCES"], } # Territoire, Quel territoire, ... place.data_source_id = source_id place.save() print(row["ID Exporter les données"], "-->", place.id) return place
def test_process_opening_hours_to_osm_format(self): opening_hours_list = [ ( "Du lundi au vendredi : 09:00-12:00 et 14:00-16:30 / Samedi : 09:00-12:00", "Mo-Fr 09:00-12:00,14:00-16:30; Sa 09:00-12:00", ), ( "Du lundi au vendredi de 8h30 à 12h et de 14h à 17h30", "Mo-Fr 08:30-12:00,14:00-17:30", ), ( "du lundi au vendredi de 9h00 à 12h00 et de 13h30 à 16h30", "Mo-Fr 09:00-12:00,13:30-16:30", ), ("8h30-12h00/13h30-17h30", "08:30-12:00,13:30-17:30"), ( "Lundi : 13h30 - 17h30 ; Mardi au Jeudi : 8h30 - 12h et 13h30 - 17h30 ; Vendredi : 8h30 - 12h et 13h30 - 16h", # "Mo 13:30-17:30; Tu-Th 08:30-12:00,13:30-17:30; Fr 08:30-12:00,13:30-16:00", "", # not managed anymore because of ";" (considers that there is 1 day per elem split) ), ( "mardi de 10h à 21h / du mercredi au vendredi de 10h à 18h / le samedi de 9h15 à 18h", "Tu 10:00-21:00; We-Fr 10:00-18:00; Sa 09:15-18:00", ), ( "Lundi au vendredi 8H00 à 17H30 et samedi 8H30 à 12H30", "Mo-Fr 08:00-17:30, Sa 08:30-12:30", ), ( "Mercredi 14h-18h; jeudi 18h-21h; vendredi 9h-12h/14h-18h; samedi 14h-18h", # "We 14:00-18:00; Th 18:00-21:00; Fr 09:00-12:00,14:00-18:00; Sa 14:00-18:00", "", # not managed anymore because of ";" (considers that there is 1 day per elem split) ), ( "Lundi 9h-12h/14h-21h; mardi 9h-12h/14h-18h;mercredi 9h-12h/14h-21h; jeudi et vendredi 9h-12h/14h-18h; samedi 9h-12h", # "Mo 09:00-12:00,14:00-21:00; Tu 09:00-12:00,14:00-18:00; We 09:00-12:00,14:00-21:00; Th, Fr 09:00-12:00,14:00-18:00; Sa 09:00-12:00", "", # not managed anymore because of ";" (considers that there is 1 day per elem split) ), ("Du lundi au samedi de 9-13h/14h-20h", "Mo-Sa 09:00-13:00,14:00-20:00"), # Array --> string with " | " seperator ( "9:00 - 12:00 / 13:30 - 17:00 | 9:00 - 12:00 / 13:30 - 17:00 | | | - | 10:00 - 13:00 | -", "Mo 09:00-12:00,13:30-17:00; Tu 09:00-12:00,13:30-17:00; Sa 10:00-13:00", ), ( "9:00 - 12:00 / 13:30 - 17:00 | 9:00 - 12:00", "Mo 09:00-12:00,13:30-17:00; Tu 09:00-12:00", ), # Array --> string with "; " seperator ( "9:00 - 12:00 / 13:30 - 17:00; 9:00 - 12:00 / 13:30 - 17:00; ; ; -; 10:00 - 13:00; -", "Mo 09:00-12:00,13:30-17:00; Tu 09:00-12:00,13:30-17:00; Sa 10:00-13:00", ), ( "9:00 - 12:00 / 13:30 - 17:00; 9:00 - 12:00", "Mo 09:00-12:00,13:30-17:00; Tu 09:00-12:00", ), # Extra days ? skip them ( "9:00-18:00; 9:00-18:00; 9:00-18:00; 9:00-18:00; 9:00-18:00; 9:00-18:00; 9:00-18:00; JF: 9:00-13:00", "Mo 09:00-18:00; Tu 09:00-18:00; We 09:00-18:00; Th 09:00-18:00; Fr 09:00-18:00; Sa 09:00-18:00; Su 09:00-18:00", ), # ( # "9:00 - 12:00 / 13:30 - 17:00", # "09:00-12:00,13:30-17:00" # ), # fail ( "du lundi au vendredi de 9 à 12 h et de 14 à 18 h, le samedi de 10 à 13 h", "", ), ( "Lundi : 9:00 - 12:00 / 13:30 - 17:00; Mardi : 9:00 - 12:00 / 13:30 - 17:00; Samedi : -", "", ), ("Mo 10:00-13:00,après-midi sur rdv", ""), ("Lundi", ""), ( [ "9h - 18h", "9h à 12h - 13h30 à 17h", "14h00 à 18h30", "9/17", "9h - 18h", "fermé", "", ], "", # "Mo 9h-18h; Tu 9h-12h,13:30-17h; We 14:00-18:30; Th 9,17; Fr 9h-18h; Sa off", ), ] for opening_hours in opening_hours_list: opening_hours_raw = opening_hours[0] opening_hours_osm_format = opening_hours[1] opening_hours_raw_processed = utilities.process_opening_hours_to_osm_format( opening_hours_raw ) self.assertIsInstance(opening_hours_raw_processed, str) self.assertEqual(opening_hours_raw_processed, opening_hours_osm_format)