Advertisement
philRG

Comment devenir fou en Python

Feb 18th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.96 KB | None | 0 0
  1.     # méthode de création d'un objet de type "Course" à partir de données d'entrées
  2.     def createCourse(self, id_course, course):
  3.         course = conversion_accents(course)
  4.         course = re.sub(regex_special_chars, ' ', course)
  5.         #print(course)
  6.         # template = "09H20 - (POTEZ JUSTINE (ADO)) Saint-Laurent-du-Var - 591 Avenue Jean Aicard - RESIDENCE ST MARC BAT 7 - 06 73 80 48 45  - 06 25 18 28 24 PERE DEST Nice 2 Rue Raynardi / CPJA <<EXO OUI BT SERIE SI HOMME PRENDS COURSE, NE PAS PARLER A JUSTINE"
  7.         tab_1 = course.split("<<")
  8.         #print(tab_1)
  9.         # payment info -> EXO OUI BT SERIE SI HOMME PRENDS COURSE, NE PAS PARLER A JUSTINE"
  10.         payment_info = tab_1[1].strip()
  11.         #print("PROUT", payment_info)
  12.         #payment_info = tab_1
  13.         # tab_2 -> template = "09H20 - (POTEZ JUSTINE (ADO)) Saint-Laurent-du-Var - 591 Avenue Jean Aicard - RESIDENCE ST MARC BAT 7 - 06 73 80 48 45  - 06 25 18 28 24 PERE DEST Nice 2 Rue Raynardi / CPJA
  14.         tab_2 = tab_1[0]
  15.         tab_3 = tab_2.split(" DEST ")
  16.         # Extraction adresse destination de la course
  17.         # tab_4 -> template = "Nice 2 Rue Raynardi / CPJA "
  18.         # tab_4 -> template = "S20 Nice  CYCLOTRON - CAL - 227 Avenue de la Lanterne "
  19.         tab_4 = tab_3[1]
  20.         tab_4_tmp = tab_4.split(" ")
  21.         is_sector_code = True if re.match(regex_code_secteur, tab_4_tmp[0]) else False
  22.         sector_code = tab_4_tmp[0].strip() if is_sector_code else ""
  23.         to_city = tab_4_tmp[1] if is_sector_code else tab_4_tmp[0]
  24.         to_street = " ".join(tab_4_tmp[2:len(tab_4_tmp)]).strip() if sector_code else " ".join(tab_4_tmp[1:len(tab_4_tmp)])
  25.         to_street = to_street.split("/")[0].strip()
  26.         to_postal_address = to_street.strip() + " " + to_city.strip()
  27.  
  28.         # Extraction informations client, heure et adresse de ramassage
  29.         # tab_5 -> template = "09H20 - (POTEZ JUSTINE (ADO)) Saint-Laurent-du-Var - 591 Avenue Jean Aicard - RESIDENCE ST MARC BAT 7 - 06 73 80 48 45  - 06 25 18 28 24 PERE
  30.         # tab_5 -> template = "09H15 - (ROBBE CLAUDE) NICE - 12 RUE DES PONCHETTES - MAISON EN FACE DE L ARCHE- PRES DU COURS SALEYA - 06 82 56 88 06 - 04 93 13 08 28  "
  31.         # tab_5 -> template = "09H00 - (CARBONI EDMON - BASTIA) NICE -  NICE AEROPORT 2 - BASTIA - 06 45 27 30 75  DEST S22 NICE  HOPITAL ARCHET 1"
  32.         tab_5 = tab_3[0]
  33.         #tab_5 = re.sub('(.')
  34.         tab_6 = tab_5.split(" - ")
  35.         #print("Phone 1", tab_6)
  36.         time = tab_6[0].strip()
  37.         # Nom contact et ville
  38.         # template = "(POTEZ JUSTINE (ADO)) Saint-Laurent-du-Var "
  39.         # template = "(CARBONI EDMON - BASTIA) NICE"
  40.         tab_field_2 = tab_6[1].strip()
  41.         tab_field_2_tmp = tab_field_2.strip().split(" ")
  42.         from_city = tab_field_2_tmp[-1]
  43.         contact_name_tmp = " ".join(tab_field_2_tmp[0:len(tab_field_2_tmp) - 1])
  44.         contact_name = contact_name_tmp[1:len(contact_name_tmp) - 1].strip()
  45.         # Adresse et complément d'adresse
  46.         from_street = tab_6[2]
  47.         from_postal_address = from_street.strip() + " " + from_city.strip()
  48.         # Numéros de tél de contact
  49.         phone_list = []
  50.         #print("Phone", tab_6)
  51.         for field in tab_6:
  52.             if re.match(regex_phone_number, field):
  53.                 phone_number = re.sub('[a-zA-Z]', '', field)
  54.                 phone_list.append(phone_number)
  55.         first_phone_no = phone_list[0]
  56.         second_phone_no = phone_list[1] if len(phone_list) == 2 else ""
  57.         position_fin_adresse = len(tab_6) - len(phone_list)
  58.         from_address_info = " - ".join(tab_6[3:position_fin_adresse])
  59.  
  60.         from_location_id = self.getLocationId(from_postal_address, sector_code, 'P')
  61.         print(from_location_id)
  62.         to_location_id = self.getLocationId(to_postal_address, sector_code, 'D')
  63.         course_Object = Course(id_course, time, from_location_id, to_location_id, contact_name, first_phone_no, second_phone_no, payment_info)
  64.  
  65.         return course_Object
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement