contact-person-profile-csv-imp-local 0.0.30__tar.gz → 0.0.32__tar.gz

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.
Files changed (13) hide show
  1. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/PKG-INFO +1 -1
  2. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/contact_person_profile_csv_imp_local/src/CSVToContactPersonProfile.py +83 -15
  3. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/contact_person_profile_csv_imp_local.egg-info/PKG-INFO +1 -1
  4. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/setup.py +1 -1
  5. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/README.md +0 -0
  6. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/contact_person_profile_csv_imp_local/src/__init__.py +0 -0
  7. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/contact_person_profile_csv_imp_local/src/contact_person_profile_csv_imp_local_constants.py +0 -0
  8. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/contact_person_profile_csv_imp_local.egg-info/SOURCES.txt +0 -0
  9. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/contact_person_profile_csv_imp_local.egg-info/dependency_links.txt +0 -0
  10. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/contact_person_profile_csv_imp_local.egg-info/requires.txt +0 -0
  11. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/contact_person_profile_csv_imp_local.egg-info/top_level.txt +0 -0
  12. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/pyproject.toml +0 -0
  13. {contact_person_profile_csv_imp_local-0.0.30 → contact_person_profile_csv_imp_local-0.0.32}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.30
3
+ Version: 0.0.32
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
@@ -46,6 +46,8 @@ 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
+ RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_ID = 60
50
+
49
51
 
50
52
  # Those methods should be called from the common method for this repo (contact-person-profile-csv-imp-local-python-package and google-contact-sync ...)
51
53
 
@@ -105,6 +107,7 @@ DEFAULT_PROFILE_ID = 0
105
107
 
106
108
  class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
107
109
  object=CSVToContactPersonProfileConstants.CSV_LOCAL_PYTHON_PACKAGE_CODE_LOGGER_OBJECT):
110
+ # TODO Shall we have the groups_str parameter in the constructor or when running the each import so we can use different groups_str for every import
108
111
  def __init__(self, groups_str: str = None, is_test_data: bool = False) -> None:
109
112
  GenericCRUD.__init__(self, default_schema_name="field", default_column_name="field_id",
110
113
  default_table_name="field_table", default_view_table_name="field_view",
@@ -128,6 +131,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
128
131
  self.domain_local = DomainLocal(is_test_data=is_test_data)
129
132
  self.importers_local = ImportersLocal()
130
133
  self.data_sources = DataSources()
134
+ self.groups_list = None
131
135
 
132
136
  # # 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"?
133
137
  # def __get_field_name(self, field_id: int, data_source_type_id: int) -> str:
@@ -163,7 +167,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
163
167
  def insert_update_contact_from_csv(
164
168
  self, *, data_source_type_id: int, file_name: str = None, user_external_username: str, system_id: int = None,
165
169
  # TODO Add support to criteria_set_id
166
- directory_name: str = None, csv_path: str = None, start_index: int = 0, end_index: int = None) -> dict:
170
+ directory_name: str = None, csv_path: str = None, start_index: int = 0, end_index: int = None,
171
+ groups_dicts: dict = None, profile_id: int = None) -> dict:
167
172
  """
168
173
  Insert contacts from CSV file to the database
169
174
  :param data_source_type_id: The data source ID
@@ -175,10 +180,20 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
175
180
  :param end_index: The end index
176
181
  :return:
177
182
  """
183
+
184
+ profile_id_by_email_address = ProfilesLocal().select_one_value_by_column_and_value(
185
+ schema_name="profile", view_table_name="profile_view",
186
+ select_clause_value="profile_id", column_name="profile.main_email_address",
187
+ column_value=user_external_username)
188
+ profile_id = profile_id or profile_id_by_email_address
189
+ self.groups_list = groups_dicts if groups_dicts else []
190
+ '''
178
191
  profile_id = ProfilesLocal().select_one_value_by_column_and_value(
179
192
  schema_name="profile", view_table_name="profile_view",
180
- select_clause_value="profile_id", column_name="profile_main_email",
193
+ select_clause_value="profile_id", column_name="profile.main_email_address",
181
194
  column_value=user_external_username)
195
+ '''
196
+ self.logger.info(f"profile_id: {profile_id}")
182
197
  # TODO Please explain
183
198
  # if csv_path is provided then we will use the full path
184
199
  # if csv_path is not provided then we will use the directory_name and file_name to create the full path
@@ -195,7 +210,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
195
210
  contact_fields_to_keep = (
196
211
  'name_prefix', 'additional_name', 'name_suffix', 'nickname', 'full_name', 'title', 'department', 'notes',
197
212
  'first_name', 'last_name', 'phone1', 'phone2', 'phone3', 'birthday', 'email1', 'email2', 'email3',
198
- 'hashtag', 'url', 'groups', 'added_timestamp',
213
+ 'hashtag', 'url', 'groups', 'added_timestamp', 'comment',
199
214
  'website1', 'handle', 'address1_street', 'address1_city', 'address1_state', 'address1_postal_code',
200
215
  'address1_country', 'address2_street', 'address2_city', 'address2_state', 'address2_postal_code',
201
216
  'address2_country', 'job_title', 'organization', 'display_as')
@@ -294,6 +309,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
294
309
  contact_dict["source"] = "Import"
295
310
  contact_dict["owner_profile_id"] = profile_id
296
311
  contact_dict["system_id"] = system_id
312
+ contact_dict = CSVToContactPersonProfile.fix_contact_dict_by_data_source_type(
313
+ contact_dict=contact_dict, data_source_type_id=data_source_type_id)
297
314
  contact_id = self.contacts_local.upsert_contact_dict(contact_dict=contact_dict)
298
315
  contact_dict["contact_id"] = contact_id
299
316
  if contact_id:
@@ -310,7 +327,6 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
310
327
 
311
328
  # TODO def insert_update_contact_groups_from_contact_notes( contact_notes: str) -> int:
312
329
  # TODO Add contact_group with seq, attribute, is_sure using group-local-python-package
313
-
314
330
  # TODO def process_people_url( people_url ) -> str:
315
331
  # TODO Use regex to extract the data from the URL
316
332
  # TODO add to user_external using user-external-python-package
@@ -481,19 +497,47 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
481
497
  contact_id = contact_dict.get("contact_id")
482
498
  groups = []
483
499
  groups_linked = None
484
- if contact_dict.get("organization"):
485
- groups.append(contact_dict.get("organization"))
486
- if contact_dict.get("job_title"):
487
- groups.append(contact_dict.get("job_title"))
500
+ organization = contact_dict.get("organization")
501
+ if organization:
502
+ organization_group_dict = {
503
+ "name": organization,
504
+ "hashtag": '#' + organization.upper(),
505
+ "is_organization": 1,
506
+ "main_group_type_id": 2000, # TODO: Shall we get it from db or from constant?
507
+ # ml table
508
+ "is_main_title": False,
509
+ "title": organization,
510
+ }
511
+ groups.append(organization_group_dict)
512
+ job_title = contact_dict.get("job_title")
513
+ if job_title:
514
+ job_title_group_dict = {
515
+ "name": job_title,
516
+ "hashtag": '#' + job_title.upper(),
517
+ "is_job_title": 1,
518
+ "main_group_type_id": 3001, # TODO: Shall we get it from db or from constant?
519
+ # ml table
520
+ "is_main_title": False,
521
+ "title": job_title,
522
+ }
523
+ groups.append(job_title_group_dict)
488
524
  if contact_dict.get("groups"):
489
525
  _groups = contact_dict.get("groups").split(", ")
490
526
  for group in _groups:
491
- groups.append(group)
527
+ group_dict = {
528
+ "name": group,
529
+ "hashtag": '#' + group.upper(),
530
+ "main_group_type_id": 0, # TODO: Shall we get it from db or from constant?
531
+ # ml table
532
+ "is_main_title": False,
533
+ "title:": group,
534
+ }
535
+ groups.append(group_dict)
492
536
  for group in self.groups_list:
493
537
  groups.append(group)
494
538
  if len(groups) > 0:
495
539
  groups_linked = self.contact_groups.insert_link_contact_group_with_group_local(
496
- contact_id=contact_id, groups_names=groups)
540
+ contact_id=contact_id, groups_dicts=groups)
497
541
 
498
542
  return groups_linked
499
543
 
@@ -618,6 +662,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
618
662
  # TODO Please change all Magic Numbers to data generated by Sql2Code
619
663
  elif data_source_type_id == 57: # BGU Course csv
620
664
  url = None
665
+ elif data_source_type_id == RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_ID:
666
+ url = None
621
667
  else:
622
668
  raise ValueError("data_source_type_id is not valid")
623
669
  importer_id = self.importers_local.insert(
@@ -693,7 +739,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
693
739
  self.logger.error("Error while getting country name by phone number",
694
740
  object=exception)
695
741
  continue
696
- currect_location_dict = {
742
+ current_location_dict = {
697
743
  "address_local_language": None,
698
744
  "city": None,
699
745
  "postal_code": None,
@@ -704,10 +750,16 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
704
750
  "state": LocationLocalConstants.DEFAULT_STATE_NAME,
705
751
  "region": LocationLocalConstants.DEFAULT_REGION_NAME,
706
752
  }
707
- proccessed_location_dicts.append(currect_location_dict)
753
+ # Before adding the location to the list, check if it's country is not already in the list
754
+ for location_dict in proccessed_location_dicts:
755
+ if location_dict.get("country") == current_location_dict.get("country"):
756
+ current_location_dict = None
757
+ break
758
+ if current_location_dict:
759
+ proccessed_location_dicts.append(current_location_dict)
708
760
  for email_address in email_addresses_list:
709
761
  country = Country.get_country_name_by_email_address(email_address)
710
- currect_location_dict = {
762
+ current_location_dict = {
711
763
  "address_local_language": None,
712
764
  "city": None,
713
765
  "postal_code": None,
@@ -718,7 +770,13 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
718
770
  "state": LocationLocalConstants.DEFAULT_STATE_NAME,
719
771
  "region": LocationLocalConstants.DEFAULT_REGION_NAME,
720
772
  }
721
- proccessed_location_dicts.append(currect_location_dict)
773
+ # Before adding the location to the list, check if it's country is not already in the list
774
+ for location_dict in proccessed_location_dicts:
775
+ if location_dict.get("country") == current_location_dict.get("country"):
776
+ current_location_dict = None
777
+ break
778
+ if current_location_dict:
779
+ proccessed_location_dicts.append(current_location_dict)
722
780
 
723
781
  return proccessed_location_dicts
724
782
 
@@ -800,9 +858,19 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
800
858
  @staticmethod
801
859
  # TODO Move this function to python-sdk
802
860
  def detect_encoding(file_path: str, data_source_type_id: int = None):
803
- if data_source_type_id == 16 or data_source_type_id == 17 or data_source_type_id == 18:
861
+ if data_source_type_id in [16, 17, 18]:
804
862
  return "utf-8"
805
863
  else:
806
864
  with open(file_path, 'rb') as f:
807
865
  result = chardet.detect(f.read())
808
866
  return result['encoding']
867
+
868
+ @staticmethod
869
+ def fix_contact_dict_by_data_source_type(contact_dict: dict, data_source_type_id: int) -> dict:
870
+ if data_source_type_id == RISHON_MUNI_EXHIBITOR_CSV_DATA_SOURCE_TYPE_ID:
871
+ if contact_dict.get('phone1'):
872
+ cellphone_number = contact_dict.get('phone1')
873
+ if cellphone_number.startswith('0'):
874
+ cellphone_number = '+972 ' + cellphone_number
875
+ contact_dict['phone1'] = cellphone_number
876
+ return contact_dict
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.30
3
+ Version: 0.0.32
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
@@ -5,7 +5,7 @@ package_dir = PACKAGE_NAME.replace("-", "_")
5
5
 
6
6
  setuptools.setup(
7
7
  name=PACKAGE_NAME,
8
- version='0.0.30', # https://pypi.org/project/contact-person-profile-csv-imp-local/
8
+ version='0.0.32', # https://pypi.org/project/contact-person-profile-csv-imp-local/
9
9
  author="Circles",
10
10
  author_email="info@circles.ai",
11
11
  description="PyPI Package for Circles CSVToContactPersonProfile-local Local/Remote Python",