contact-person-profile-csv-imp-local 0.0.28__py3-none-any.whl → 0.0.29__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.
@@ -1,3 +1,4 @@
1
+ # TODO Please rename the file based on our naming convention i.e. contact_person
1
2
  import csv
2
3
  import os
3
4
  from datetime import datetime
@@ -103,13 +104,14 @@ DEFAULT_PROFILE_ID = 0
103
104
 
104
105
  class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
105
106
  object=CSVToContactPersonProfileConstants.CSV_LOCAL_PYTHON_PACKAGE_CODE_LOGGER_OBJECT):
106
- def __init__(self, is_test_data: bool = False) -> None:
107
+ def __init__(self, groups_str: str = None, is_test_data: bool = False) -> None:
107
108
  GenericCRUD.__init__(self, default_schema_name="field", default_column_name="field_id",
108
109
  default_table_name="field_table", default_view_table_name="field_view",
109
110
  is_test_data=is_test_data)
110
111
  self.contact_entity_type_id = self.select_one_value_by_column_and_value(
111
112
  schema_name="entity_type", view_table_name="entity_type_ml_en_view",
112
113
  select_clause_value="entity_type_id", column_name="title", column_value="Contact")
114
+ self.groups_list: list[str] = [group.strip() for group in groups_str.split(",")] if groups_str else []
113
115
  self.user_context = UserContext()
114
116
  self.organization_profiles = OrganizationProfilesLocal(is_test_data=is_test_data)
115
117
  self.contact_persons = ContactPersonsLocal(is_test_data=is_test_data)
@@ -155,6 +157,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
155
157
  # ans: it cannot be after directory_name and csv_path because it is a required parameter
156
158
 
157
159
  # TODO: break this function into smaller functions
160
+ # TODO Align the parameters between import-contact-csv with sync-google-contact
161
+ # 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?
158
162
  def insert_update_contact_from_csv(
159
163
  self, *, data_source_type_id: int, file_name: str = None, user_external_username: str,
160
164
  # TODO Add support to criteria_set_id
@@ -183,6 +187,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
183
187
  if not os.path.exists(csv_file_path):
184
188
  raise FileNotFoundError(f"File {csv_file_path} not found")
185
189
 
190
+ # TODO Why do we need it? - Those fields will be added to the contact_dict
186
191
  contact_fields_to_keep = (
187
192
  'name_prefix', 'additional_name', 'name_suffix', 'nickname', 'full_name', 'title', 'department', 'notes',
188
193
  'first_name', 'last_name', 'phone1', 'phone2', 'phone3', 'birthday', 'email1', 'email2', 'email3',
@@ -302,6 +307,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
302
307
  # TODO Use regex to extract the data from the URL
303
308
  # TODO add to user_external using user-external-python-package
304
309
 
310
+ # TODO This looks like a generic method, please move it to url-remote-python-package
305
311
  @staticmethod
306
312
  def process_url(original_url: str) -> str:
307
313
  prefixes = ['http://', 'https://'] # noqa
@@ -316,6 +322,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
316
322
 
317
323
  # TODO: add a method to add notes to text_block process them to retrieve the groups and create and link the groups to the user
318
324
 
325
+ # TODO Please change ALL methods which are not public to become private
319
326
  def process_notes(self, contact_note: str) -> None:
320
327
  # TODO number_of_system_recommednded_groups_identified_in_contact_notes = get_system_recommended_groups_from_contact_notes( contact_notes: str)
321
328
 
@@ -333,6 +340,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
333
340
 
334
341
  pass
335
342
 
343
+
344
+ # TODO Please move this method if not exists to LocationsLocal
345
+ # TODO get_location_type_id_by_location_name(
346
+ # This method is being used by import-csv-contact
336
347
  def get_location_type_id_by_name(self, location_type_name: str) -> int or None:
337
348
  """
338
349
  Get the location type ID by its name
@@ -344,6 +355,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
344
355
  select_clause_value="location_type_id", column_name="title", column_value=location_type_name)
345
356
  return location_type_id
346
357
 
358
+ # TODO Move this method to ContactsLocal class in contact-local
359
+ # This method is being used by import-csv-contact
347
360
  def __insert_contact_details_to_db(self, *, contact_dict: dict, user_external_id: int,
348
361
  data_source_instance_id: int, data_source_type_id: int) -> int:
349
362
 
@@ -352,7 +365,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
352
365
 
353
366
  # insert link contact_location
354
367
  # The location is in contact_dict
368
+ # TODO Can we have a better name for locations_results? Maybe contact_locations?
355
369
  location_results = self.__insert_link_contact_location(contact_dict=contact_dict) or [{}]
370
+ # TODO Why do we process only [0]? What if there are multiple locations?
371
+ # TODO If we don't suppose multiple locations, maybe we should change it to contact_dict["main_location_id"] as we do in other places
356
372
  contact_dict["location_id"] = location_results[0].get("location_id")
357
373
  contact_dict["country_id"] = location_results[0].get("country_id")
358
374
 
@@ -396,6 +412,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
396
412
  )
397
413
  return importer_id
398
414
 
415
+ # TODO Move this method to LocationsLocal
416
+ # This method is being used by import-csv-contact
399
417
  def __insert_organization(self, contact_dict: dict) -> int or None:
400
418
 
401
419
  if not contact_dict.get("organization"):
@@ -440,6 +458,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
440
458
 
441
459
  return organization_dict
442
460
 
461
+ # TODO When do we use it? Multiple profiles to one organization?
443
462
  def __insert_organization_profile(self, organization_id: int, profiles_ids_list: list[int]) -> list[int] or None:
444
463
 
445
464
  if not organization_id or not profiles_ids_list:
@@ -462,6 +481,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
462
481
  _groups = contact_dict.get("groups").split(", ")
463
482
  for group in _groups:
464
483
  groups.append(group)
484
+ for group in self.groups_list:
485
+ groups.append(group)
465
486
  if len(groups) > 0:
466
487
  groups_linked = self.contact_groups.insert_link_contact_group_with_group_local(
467
488
  contact_id=contact_id, groups_names=groups)
@@ -568,12 +589,15 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
568
589
  location_dicts = self.__procces_location_of_contact(contact_dict)
569
590
  if not location_dicts:
570
591
  return
571
- location_results = [self.contact_location.insert_contact_and_link_to_location(
572
- location_dict=location_dict, contact_id=contact_id)
573
- for location_dict in location_dicts]
574
-
575
- return location_results
576
-
592
+ locations_results = []
593
+ for location_dict in location_dicts:
594
+ location_results = self.contact_location.insert_contact_and_link_to_location(
595
+ location_dict=location_dict, contact_id=contact_id)
596
+ if location_results:
597
+ locations_results.append(location_results)
598
+ return locations_results
599
+
600
+ # TODO merge this method with the method in google-contact-sync
577
601
  def __insert_importer(self, contact_id: int, location_id: int, user_external_id: int,
578
602
  data_source_type_id: int, data_source_instance_id: int) -> int:
579
603
  # TODO: Shall we consider the url of csv's as the following? Use Sql2Code. Use const enum
@@ -583,7 +607,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
583
607
  url = "www.outlook.com"
584
608
  elif data_source_type_id == 18:
585
609
  url = "www.linkedin.com"
586
- elif data_source_type_id == 57:
610
+ # TODO Please change all Magic Numbers to data generated by Sql2Code
611
+ elif data_source_type_id == 57: # BGU Course csv
587
612
  url = None
588
613
  else:
589
614
  raise ValueError("data_source_type_id is not valid")
@@ -598,6 +623,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
598
623
 
599
624
  return importer_id
600
625
 
626
+ # TODO Move this method to ContactsLocal if not exists already
601
627
  def __procces_location_of_contact(self, contact_dict: dict) -> dict or None:
602
628
  """
603
629
  Process location of Google contact
@@ -689,6 +715,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
689
715
  return proccessed_location_dicts
690
716
 
691
717
  @staticmethod
718
+ # TODO Move this method to LocationsLocal if not exists already
692
719
  def __create_location_dict(*, address_street: str, address_city: str, address_postal_code: str,
693
720
  address_country: str, address_state: str) -> dict:
694
721
  location_dict = {
@@ -706,12 +733,14 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
706
733
  return location_dict
707
734
 
708
735
  @staticmethod
736
+ # Move this method to ContactsLocal if not exists already
709
737
  def __get_phone_numbers_list(contact_dict: dict) -> list:
710
738
  phones_list = [contact_dict.get(f"phone{i}")
711
739
  for i in range(1, 4) if contact_dict.get(f"phone{i}")]
712
740
  return phones_list
713
741
 
714
742
  @staticmethod
743
+ # Move this method to ContactsLocal if not exists already
715
744
  def __get_email_addresses_list(contact_dict: dict) -> list:
716
745
  emails_list = [contact_dict.get(f"email{i}")
717
746
  for i in range(1, 4) if contact_dict.get(f"email{i}")]
@@ -736,6 +765,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
736
765
 
737
766
  return user_external_id
738
767
 
768
+ # Move this method to DataSourceInstancesLocal in data-source-instance-local-python-package
739
769
  def __get_data_source_instance_id(self, data_source_type_id: int, csv_file_path: str, user_external_id: int,
740
770
  file_name: str,
741
771
  user_external_username: str, start_index: int, end_index: int) -> int:
@@ -760,6 +790,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
760
790
  return data_source_instance_id
761
791
 
762
792
  @staticmethod
793
+ # TODO Move this function to python-sdk
763
794
  def detect_encoding(file_path: str, data_source_type_id: int = None):
764
795
  if data_source_type_id == 16 or data_source_type_id == 17 or data_source_type_id == 18:
765
796
  return "utf-8"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.28
3
+ Version: 0.0.29
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
@@ -1,7 +1,7 @@
1
- contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=KlaCY4YDlMu77bZLF7sIXHiYLfiDu7scds_CyS4ugMc,41462
1
+ contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=5Z7Ry0pXftYx5t2c5M-SamiFLdtfHvd7mA9Mf6s11Xg,43690
2
2
  contact_person_profile_csv_imp_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
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.28.dist-info/METADATA,sha256=ZpO8eNNPmyDib3wNYdxIMAcK5faKxhghbPHKYQC3cK8,1481
5
- contact_person_profile_csv_imp_local-0.0.28.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- contact_person_profile_csv_imp_local-0.0.28.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
- contact_person_profile_csv_imp_local-0.0.28.dist-info/RECORD,,
4
+ contact_person_profile_csv_imp_local-0.0.29.dist-info/METADATA,sha256=QjTN4mavxPgwRaXO8td-zu5qudljl67ZukaNjmKZqZE,1481
5
+ contact_person_profile_csv_imp_local-0.0.29.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ contact_person_profile_csv_imp_local-0.0.29.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
+ contact_person_profile_csv_imp_local-0.0.29.dist-info/RECORD,,