contact-person-profile-csv-imp-local 0.0.34__py3-none-any.whl → 0.0.35__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,12 +46,6 @@ CONTACT_PERSON_PROFILE_CSV_SYSTEM_ID = 1
46
46
  DEFAULT_LOCATION_ID = LocationLocalConstants.UNKNOWN_LOCATION_ID
47
47
  DEFAULT_PROFILE_ID = 0
48
48
 
49
- GOOGLE_CSV_DATA_SOURCE_TYPE_ID = 16
50
- OUTLOOK_CSV_DATA_SOURCE_TYPE_ID = 17
51
- LINKEDIN_CSV_DATA_SOURCE_TYPE_ID = 18
52
- BGU_COURSE_CSV_DATA_SOURCE_TYPE_ID = 57
53
- RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_ID = 60
54
-
55
49
 
56
50
  # Those methods should be called from the common method for this repo (contact-person-profile-csv-imp-local-python-package and google-contact-sync ...)
57
51
 
@@ -136,6 +130,16 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
136
130
  self.importers_local = ImportersLocal()
137
131
  self.data_sources = DataSources()
138
132
  self.groups_list = None
133
+ self.unknown_main_group_type_id = self.select_one_value_by_column_and_value(
134
+ schema_name='group', view_table_name='group_type_ml_view',
135
+ select_clause_value='group_type_id', column_name='title', column_value='Unknown')
136
+ self.organization_main_group_type_id = self.select_one_value_by_column_and_value(
137
+ schema_name='group', view_table_name='group_type_ml_view',
138
+ select_clause_value='group_type_id', column_name='title', column_value='Organization')
139
+ self.job_title_main_group_type_id = self.select_one_value_by_column_and_value(
140
+ schema_name='group', view_table_name='group_type_ml_view',
141
+ select_clause_value='group_type_id', column_name='title', column_value='Job Title')
142
+
139
143
 
140
144
  # # TODO Does this function should be here on in https://github.com/circles-zone/variable-local-python-package/tree/dev/variable_local_python_package/variable_local/src "field/field.py"?
141
145
  # def __get_field_name(self, field_id: int, data_source_type_id: int) -> str:
@@ -169,26 +173,36 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
169
173
  # TODO Align the parameters between import-contact-csv with sync-google-contact
170
174
  # TODO Can we please add groups_str parameter to both sync-google-contact and import-contact-csv where we add all contacts to those groups?
171
175
  def insert_update_contact_from_csv(
172
- self, *, data_source_type_id: int, file_name: str = None, user_external_username: str, system_id: int = None,
176
+ self, *, data_source_type_name: str, file_name: str = None, user_external_username: str, system_name: str = None,
173
177
  # TODO Add support to criteria_set_id
174
178
  directory_name: str = None, csv_path: str = None, start_index: int = 0, end_index: int = None,
175
- groups_dicts: dict = None, profile_id: int = None) -> dict:
179
+ groups_dicts: list[dict] = None, profile_id: int = None) -> dict:
176
180
  """
177
181
  Insert contacts from CSV file to the database
178
- :param data_source_type_id: The data source ID
182
+ :param data_source_type_name: The data source name
179
183
  :param file_name: The CSV file name
180
184
  :param user_external_username: The user external username
185
+ :param system_name: The system name
186
+ :param user_external_username: The user external username
187
+ :param groups_dicts: The groups list
188
+ :param profile_id: The profile ID
181
189
  :param directory_name: The CSV file directory name if it wasn't given it will search for the file in the same directory
182
190
  :param csv_path: The CSV file path if it wasn't given it will search for the file in the same directory
183
191
  :param start_index: The start index
184
192
  :param end_index: The end index
185
193
  :return:
186
194
  """
187
-
195
+ data_source_type_id = DataSources().get_data_source_type_id_by_name(data_source_type_name)
188
196
  profile_id_by_email_address = ProfilesLocal().select_one_value_by_column_and_value(
189
197
  schema_name="profile", view_table_name="profile_view",
190
198
  select_clause_value="profile_id", column_name="profile.main_email_address",
191
199
  column_value=user_external_username)
200
+ system_id = CONTACT_PERSON_PROFILE_CSV_SYSTEM_ID
201
+ if system_name:
202
+ system_id = self.select_one_value_by_column_and_value(
203
+ schema_name="system", view_table_name="system_ml_view",
204
+ select_clause_value="system_id", column_name="title", column_value=system_name)
205
+ self.set_schema(schema_name="field")
192
206
  profile_id = profile_id or profile_id_by_email_address
193
207
  self.groups_list = groups_dicts if groups_dicts else []
194
208
  '''
@@ -219,7 +233,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
219
233
  'address1_country', 'address2_street', 'address2_city', 'address2_state', 'address2_postal_code',
220
234
  'address2_country', 'job_title', 'organization', 'display_as')
221
235
 
222
- user_external_id = self.__get_user_external_id(user_external_username=user_external_username, profile_id=profile_id)
236
+ user_external_id = self.__get_user_external_id(user_external_username=user_external_username,
237
+ profile_id=profile_id, system_id=system_id)
223
238
  # We create a new data_source_instance_id everytime we import a new csv file
224
239
  data_source_instance_id = self.__get_data_source_instance_id(
225
240
  data_source_type_id=data_source_type_id, csv_file_path=csv_file_path,
@@ -310,12 +325,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
310
325
  # TODO We should take care of situation which the contact already exists and we need to update it
311
326
  contact_dict["data_source_instance_id"] = data_source_instance_id
312
327
  contact_dict["data_source_type_id"] = data_source_type_id
313
- source_str = self.get_data_source_type_name_by_data_source_type_id(data_source_type_id) or "CSV Import"
314
- contact_dict["source"] = source_str
328
+ contact_dict["source"] = data_source_type_name
315
329
  contact_dict["owner_profile_id"] = profile_id
316
330
  contact_dict["system_id"] = system_id
317
331
  contact_dict = CSVToContactPersonProfile.fix_contact_dict_by_data_source_type(
318
- contact_dict=contact_dict, data_source_type_id=data_source_type_id)
332
+ contact_dict=contact_dict)
319
333
  contact_id = self.contacts_local.upsert_contact_dict(contact_dict=contact_dict)
320
334
  contact_dict["contact_id"] = contact_id
321
335
  if contact_id:
@@ -437,7 +451,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
437
451
  contact_id=contact_dict.get("contact_id"), location_id=contact_dict.get("location_id") or DEFAULT_LOCATION_ID,
438
452
  user_external_id=user_external_id,
439
453
  data_source_instance_id=data_source_instance_id,
440
- data_source_type_id=data_source_type_id
454
+ data_source_type_id=data_source_type_id,
455
+ data_source_type_name=contact_dict.get("source")
441
456
  )
442
457
  return importer_id
443
458
 
@@ -505,11 +520,12 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
505
520
  organization = contact_dict.get("organization")
506
521
  if organization:
507
522
  organization_group_dict = {
523
+ # table:
508
524
  "name": organization,
509
525
  "hashtag": '#' + organization.upper(),
510
526
  "is_organization": 1,
511
- "main_group_type_id": 2000, # TODO: Shall we get it from db or from constant?
512
- # ml table
527
+ "main_group_type_id": self.organization_main_group_type_id,
528
+ # ml table:
513
529
  "is_main_title": False,
514
530
  "title": organization,
515
531
  }
@@ -517,11 +533,12 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
517
533
  job_title = contact_dict.get("job_title")
518
534
  if job_title:
519
535
  job_title_group_dict = {
536
+ # table:
520
537
  "name": job_title,
521
538
  "hashtag": '#' + job_title.upper(),
522
539
  "is_job_title": 1,
523
- "main_group_type_id": 3001, # TODO: Shall we get it from db or from constant?
524
- # ml table
540
+ "main_group_type_id": self.job_title_main_group_type_id,
541
+ # ml table:
525
542
  "is_main_title": False,
526
543
  "title": job_title,
527
544
  }
@@ -530,10 +547,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
530
547
  _groups = contact_dict.get("groups").split(", ")
531
548
  for group in _groups:
532
549
  group_dict = {
550
+ # table:
533
551
  "name": group,
534
552
  "hashtag": '#' + group.upper(),
535
- "main_group_type_id": 0, # TODO: Shall we get it from db or from constant?
536
- # ml table
553
+ "main_group_type_id": self.unknown_main_group_type_id,
554
+ # ml table:
537
555
  "is_main_title": False,
538
556
  "title:": group,
539
557
  }
@@ -610,6 +628,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
610
628
  contact_dict=contact_dict,
611
629
  contact_email_address=contact_dict["email1"],
612
630
  contact_id=contact_id,
631
+ system_id=contact_dict.get("system_id"),
613
632
  user_external_dict={"username": contact_dict["email1"]}
614
633
  )
615
634
 
@@ -656,18 +675,19 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
656
675
 
657
676
  # TODO merge this method with the method in google-contact-sync
658
677
  def __insert_importer(self, contact_id: int, location_id: int, user_external_id: int,
659
- data_source_type_id: int, data_source_instance_id: int) -> int:
678
+ data_source_type_id: int, data_source_instance_id: int,
679
+ data_source_type_name: str) -> int:
660
680
  # TODO: Shall we consider the url of csv's as the following? Use Sql2Code. Use const enum
661
- if data_source_type_id == GOOGLE_CSV_DATA_SOURCE_TYPE_ID:
681
+ if data_source_type_name == CSVToContactPersonProfileConstants.GOOGLE_CSV_DATA_SOURCE_TYPE_NAME:
662
682
  url = "www.google.com"
663
- elif data_source_type_id == OUTLOOK_CSV_DATA_SOURCE_TYPE_ID:
683
+ elif data_source_type_name == CSVToContactPersonProfileConstants.OUTLOOK_CSV_DATA_SOURCE_TYPE_NAME:
664
684
  url = "www.outlook.com"
665
- elif data_source_type_id == LINKEDIN_CSV_DATA_SOURCE_TYPE_ID:
685
+ elif data_source_type_name == CSVToContactPersonProfileConstants.LINKEDIN_CSV_DATA_SOURCE_TYPE_NAME:
666
686
  url = "www.linkedin.com"
667
687
  # TODO Please change all Magic Numbers to data generated by Sql2Code
668
- elif data_source_type_id == BGU_COURSE_CSV_DATA_SOURCE_TYPE_ID:
688
+ elif data_source_type_name == CSVToContactPersonProfileConstants.BGU_COURSE_CSV_DATA_SOURCE_TYPE_NAME:
669
689
  url = None
670
- elif data_source_type_id == RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_ID:
690
+ elif data_source_type_name == CSVToContactPersonProfileConstants.RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_NAME:
671
691
  url = None
672
692
  else:
673
693
  raise ValueError("data_source_type_id is not valid")
@@ -818,7 +838,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
818
838
  # TODO use enum const for "email1" ....
819
839
  return emails_list
820
840
 
821
- def __get_user_external_id(self, user_external_username: str, profile_id: int) -> int or None:
841
+ def __get_user_external_id(self, user_external_username: str, profile_id: int, system_id: int) -> int or None:
822
842
 
823
843
  user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
824
844
  select_clause_value="user_external_id", column_name="username",
@@ -827,7 +847,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
827
847
  self.user_externals_local.insert_or_update_user_external_access_token(
828
848
  username=user_external_username,
829
849
  profile_id=profile_id,
830
- system_id=CONTACT_PERSON_PROFILE_CSV_SYSTEM_ID,
850
+ system_id=system_id,
831
851
  access_token=""
832
852
  )
833
853
  user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
@@ -871,23 +891,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
871
891
  return result['encoding']
872
892
 
873
893
  @staticmethod
874
- def fix_contact_dict_by_data_source_type(contact_dict: dict, data_source_type_id: int) -> dict:
875
- if data_source_type_id == RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_ID:
894
+ def fix_contact_dict_by_data_source_type(contact_dict: dict) -> dict:
895
+ if contact_dict.get('source') == CSVToContactPersonProfileConstants.RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_NAME:
876
896
  if contact_dict.get('phone1'):
877
897
  cellphone_number = contact_dict.get('phone1')
878
898
  if cellphone_number.startswith('0'):
879
899
  cellphone_number = '+972 ' + cellphone_number
880
900
  contact_dict['phone1'] = cellphone_number
881
901
  return contact_dict
882
-
883
- def get_data_source_type_name_by_data_source_type_id(self, data_source_type_id: int) -> str:
884
- if data_source_type_id == GOOGLE_CSV_DATA_SOURCE_TYPE_ID:
885
- return "Google Contact CSV File"
886
- elif data_source_type_id == OUTLOOK_CSV_DATA_SOURCE_TYPE_ID:
887
- return "Outlook Contact CSV File"
888
- elif data_source_type_id == LINKEDIN_CSV_DATA_SOURCE_TYPE_ID:
889
- return "Linkedin Contact CSV File"
890
- elif data_source_type_id == BGU_COURSE_CSV_DATA_SOURCE_TYPE_ID:
891
- return "BGU Course CSV File"
892
- elif data_source_type_id == RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_ID:
893
- return "Rishon Muni Exhibitor CSV File"
@@ -19,3 +19,9 @@ class CSVToContactPersonProfileConstants:
19
19
  'testing_framework': LoggerComponentEnum.testingFramework.pytest.value,
20
20
  'developer_email': DEVELOPER_EMAIL
21
21
  }
22
+
23
+ GOOGLE_CSV_DATA_SOURCE_TYPE_NAME = 'Google Contact CSV File'
24
+ LINKEDIN_CSV_DATA_SOURCE_TYPE_NAME = 'Linkedin Contact CSV File'
25
+ OUTLOOK_CSV_DATA_SOURCE_TYPE_NAME = 'Outlook Contact CSV File'
26
+ BGU_COURSE_CSV_DATA_SOURCE_TYPE_NAME = 'BGU Course CSV File'
27
+ RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_NAME = 'Rishon Muni Exhibitor CSV File'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.34
3
+ Version: 0.0.35
4
4
  Summary: PyPI Package for Circles CSVToContactPersonProfile-local Local/Remote Python
5
5
  Home-page: https://github.com/circles-zone/contact-person-profile-csv-imp-local-python-package
6
6
  Author: Circles
@@ -0,0 +1,7 @@
1
+ contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=ZXPVnc_-iuqzidpicisiBAbaaMxUATZ1CSSscbLeFbg,49712
2
+ contact_person_profile_csv_imp_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ contact_person_profile_csv_imp_local/contact_person_profile_csv_imp_local_constants.py,sha256=hlZiM-gHlVNkBvpNcILlyZE1A25Zutnb3TGO1jcdzWc,1311
4
+ contact_person_profile_csv_imp_local-0.0.35.dist-info/METADATA,sha256=uqp041W_GgsFW49pVB7-k5N6gQWFUJvOEaIzaqMb-24,1481
5
+ contact_person_profile_csv_imp_local-0.0.35.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ contact_person_profile_csv_imp_local-0.0.35.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
+ contact_person_profile_csv_imp_local-0.0.35.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=cxk42Vth14ipxbeoUnoQLkqMpsn54dF3_gD23c99_Zw,48853
2
- contact_person_profile_csv_imp_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- contact_person_profile_csv_imp_local/contact_person_profile_csv_imp_local_constants.py,sha256=eE0Bg2dCPrmG72K20k0_KOckc61C9cGSgH0Zgae_lbk,957
4
- contact_person_profile_csv_imp_local-0.0.34.dist-info/METADATA,sha256=cHbEqwedaJa_MQZgK4dPOj8tw1rElGFV1QHw6Ts6FFA,1481
5
- contact_person_profile_csv_imp_local-0.0.34.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- contact_person_profile_csv_imp_local-0.0.34.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
- contact_person_profile_csv_imp_local-0.0.34.dist-info/RECORD,,