contact-person-profile-csv-imp-local 0.0.45__py3-none-any.whl → 0.0.46__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.
@@ -2,6 +2,7 @@
2
2
  import csv
3
3
  import os
4
4
  from datetime import datetime
5
+ import sys
5
6
  from zoneinfo import ZoneInfo
6
7
  import chardet
7
8
 
@@ -103,24 +104,37 @@ DEFAULT_PROFILE_ID = 0
103
104
  # TODO def process_website
104
105
 
105
106
 
106
- class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
107
- object=CSVToContactPersonProfileConstants.CSV_LOCAL_PYTHON_PACKAGE_CODE_LOGGER_OBJECT):
107
+ class CSVToContactPersonProfile(
108
+ GenericCRUD, metaclass=MetaLogger,
109
+ object=CSVToContactPersonProfileConstants.CSV_LOCAL_PYTHON_PACKAGE_CODE_LOGGER_OBJECT):
108
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
109
- def __init__(self, groups_str: str = None, is_test_data: bool = False) -> None:
111
+ def __init__(self, groups_str: str = None,
112
+ is_test_data: bool = False) -> None:
110
113
  self._instances = {}
111
- self.classes = [ContactsLocal, OrganizationProfilesLocal, ContactPersonsLocal, ContactUserExternalLocal,
112
- ContactProfilesLocal, ContactGroups, ContactEmailAdressesLocal, ContactPhoneLocal,
113
- ContactLocationLocal, UserExternalsLocal, OrganizationsLocal, DomainLocal, ImportersLocal]
114
- self.instances_names = ['contacts_local', 'organization_profiles', 'contact_persons', 'contact_user_external',
115
- 'contact_profiles', 'contact_groups', 'contact_email_addresses', 'contact_phone',
116
- 'contact_location', 'user_externals_local', 'organizations_local', 'domain_local',
114
+ self.classes = [ContactsLocal, OrganizationProfilesLocal,
115
+ ContactPersonsLocal, ContactUserExternalLocal,
116
+ ContactProfilesLocal, ContactGroups,
117
+ ContactEmailAdressesLocal, ContactPhoneLocal,
118
+ ContactLocationLocal, UserExternalsLocal,
119
+ OrganizationsLocal, DomainLocal, ImportersLocal]
120
+ self.instances_names = ['contacts_local', 'organization_profiles',
121
+ 'contact_persons', 'contact_user_external',
122
+ 'contact_profiles', 'contact_groups',
123
+ 'contact_email_addresses', 'contact_phone',
124
+ 'contact_location', 'user_externals_local',
125
+ 'organizations_local', 'domain_local',
117
126
  'importers_local']
118
- GenericCRUD.__init__(self, default_schema_name="field", default_column_name="field_id",
119
- default_table_name="field_table", default_view_table_name="field_view",
127
+ GenericCRUD.__init__(self, default_schema_name="field",
128
+ default_column_name="field_id",
129
+ default_table_name="field_table",
130
+ default_view_table_name="field_view",
120
131
  is_test_data=is_test_data)
121
- self.contact_entity_type_id = self.select_one_value_by_column_and_value(
122
- schema_name="entity_type", view_table_name="entity_type_ml_en_view",
123
- select_clause_value="entity_type_id", column_name="title", column_value="Contact")
132
+ self.contact_entity_type_id = \
133
+ self.select_one_value_by_column_and_value(
134
+ schema_name="entity_type",
135
+ view_table_name="entity_type_ml_en_view",
136
+ select_clause_value="entity_type_id", column_name="title",
137
+ column_value="Contact")
124
138
  self.list_of_group_dicts: list[str] = [group.strip() for group in groups_str.split(",")] if groups_str else []
125
139
  self.user_context = UserContext()
126
140
  self.organization_profiles: OrganizationProfilesLocal = None
@@ -159,7 +173,6 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
159
173
  # Otherwise, return the value
160
174
  return value
161
175
 
162
-
163
176
  # # 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"?
164
177
  # def __get_field_name(self, field_id: int, data_source_type_id: int) -> str:
165
178
  # """
@@ -192,7 +205,9 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
192
205
  # TODO Align the parameters between import-contact-csv with sync-google-contact
193
206
  # 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?
194
207
  def insert_update_contact_from_csv(
195
- self, *, user_external_username: str, email_address: str, data_source_type_id: int, file_name: str = None, system_id: int = None,
208
+ self, *, user_external_username: str, email_address: str,
209
+ data_source_type_id: int, file_name: str = None,
210
+ system_id: int = None,
196
211
  # TODO Add support to criteria_set_id
197
212
  directory_name: str = None, csv_path: str = None, start_index: int = 0, end_index: int = None,
198
213
  list_of_group_dicts: list[dict] = None) -> dict:
@@ -209,7 +224,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
209
224
  :param csv_path: The CSV file path if it wasn't given it will search for the file in the same directory
210
225
  :param start_index: The start index
211
226
  :param end_index: The end index
212
- :return:
227
+ :return:
213
228
  """
214
229
  data_source_type_name = DataSources().get_data_source_name_by_id(data_source_type_id)
215
230
  # TODO There can be multiple profiles with the same email, why not to query `user_external_table`.`main_profile_id`?
@@ -217,7 +232,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
217
232
  # and may have to insert a new record to user_external_table, in this case we need profile_id from profile_view
218
233
  profile_id = self.select_one_value_by_column_and_value(
219
234
  schema_name="user_external", view_table_name="user_external_view",
220
- select_clause_value="main_profile_id", column_name="username", column_value=user_external_username)
235
+ select_clause_value="main_profile_id", column_name="username",
236
+ column_value=user_external_username)
221
237
  if profile_id is None:
222
238
  profile_id = ProfilesLocal().select_one_value_by_column_and_value(
223
239
  schema_name="profile", view_table_name="profile_view",
@@ -357,7 +373,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
357
373
  contact_dict["contact_id"] = contact_id
358
374
  if contact_id:
359
375
  self.__insert_contact_details_to_db(
360
- contact_dict=contact_dict, user_external_id=user_external_id,
376
+ contact_dict=contact_dict,
377
+ user_external_id=user_external_id,
361
378
  data_source_instance_id=data_source_instance_id,
362
379
  data_source_type_id=data_source_type_id)
363
380
  contact_data_by_contact_id_dict[contact_id] = contact_dict
@@ -406,7 +423,6 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
406
423
 
407
424
  pass
408
425
 
409
-
410
426
  # TODO Please move this method if not exists to LocationsLocal
411
427
  # TODO get_location_type_id_by_location_name(
412
428
  # This method is being used by import-csv-contact
@@ -414,7 +430,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
414
430
  """
415
431
  Get the location type ID by its name
416
432
  :param location_type_name: The location type name
417
- :return: The location type ID
433
+ :return: The location type ID
418
434
  """
419
435
  location_type_id = self.select_one_value_by_column_and_value(
420
436
  schema_name="location", view_table_name="location_type_ml_view",
@@ -434,7 +450,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
434
450
  # TODO Can we have a better name for locations_results? Maybe contact_locations?
435
451
  location_results = self.__insert_link_contact_location(contact_dict=contact_dict) or [{}]
436
452
  # TODO Why do we process only [0]? What if there are multiple locations?
437
- # 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
453
+ # TODO If we don't suppose multiple locations, maybe we should change
454
+ # it to contact_dict["main_location_id"] as we do in other places
438
455
  contact_dict["location_id"] = location_results[0].get("location_id")
439
456
  contact_dict["country_id"] = location_results[0].get("country_id")
440
457
 
@@ -442,7 +459,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
442
459
  self.__insert_link_contact_groups(contact_dict=contact_dict)
443
460
 
444
461
  # insert link contact_persons
445
- contact_person_result_dict = self.__insert_link_contact_persons(contact_dict=contact_dict) or {}
462
+ contact_person_result_dict = self.__insert_link_contact_persons(
463
+ contact_dict=contact_dict) or {}
446
464
  contact_dict["person_id"] = contact_person_result_dict.get("person_id")
447
465
 
448
466
  # insert link contact_profiles
@@ -465,7 +483,14 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
465
483
  self.__insert_link_contact_phones(contact_dict=contact_dict)
466
484
 
467
485
  # inset link contact_user_externals
468
- self.__insert_link_contact_user_external(contact_dict=contact_dict)
486
+ # old
487
+ # self.__insert_link_contact_user_external(contact_dict=contact_dict)
488
+ # new
489
+ user_external_dict = {}
490
+ user_external_dict["user_external_id"] = user_external_id
491
+ self.__insert_link_contact_user_external_by_contact_dict_and_user_external_dict(
492
+ contact_dict=contact_dict,
493
+ user_external_dict=user_external_dict)
469
494
 
470
495
  # insert link contact_internet_domains
471
496
  self.__insert_link_contact_domains(contact_dict=contact_dict)
@@ -524,13 +549,16 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
524
549
  return organization_dict
525
550
 
526
551
  # TODO When do we use it? Multiple profiles to one organization?
527
- def __insert_organization_profile(self, organization_id: int, profiles_ids_list: list[int]) -> list[int] or None:
552
+ def __insert_organization_profile(self, organization_id: int,
553
+ profiles_ids_list: list[int]) -> list[int] or None:
528
554
 
529
555
  if not organization_id or not profiles_ids_list:
530
556
  return None
531
557
 
532
- organization_profiles_ids = self.organization_profiles.insert_multiple_mappings_if_not_exists(
533
- organizations_ids=[organization_id], profiles_ids=profiles_ids_list)
558
+ organization_profiles_ids = \
559
+ self.organization_profiles.insert_multiple_mappings_if_not_exists(
560
+ organizations_ids=[organization_id],
561
+ profiles_ids=profiles_ids_list)
534
562
 
535
563
  return organization_profiles_ids
536
564
 
@@ -571,7 +599,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
571
599
  for group in _groups:
572
600
  group_dict = {
573
601
  # table:
574
- "name": group, # TODO We need to translate to English
602
+ "name": group, # TODO We need to translate to English
575
603
  "hashtag": '#' + group.upper(),
576
604
  "main_group_type_id": self.unknown_main_group_type_id,
577
605
  # ml table:
@@ -648,23 +676,45 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
648
676
 
649
677
  return contact_phone_ids
650
678
 
679
+ # old, TODO, do we need it?
651
680
  def __insert_link_contact_user_external(self, contact_dict: dict) -> int:
652
681
  contact_id = contact_dict.get("contact_id")
653
- contact_user_external_id = self.contact_user_external.insert_contact_and_link_to_existing_or_new_user_external(
654
- contact_dict=contact_dict,
655
- contact_email_address_str=contact_dict["email1"],
656
- contact_id=contact_id,
657
- system_id=contact_dict.get("system_id"),
658
- user_external_dict={"username": contact_dict["email1"]}
659
- )
682
+ print("Before " + __name__, file=sys.stderr, flush=True)
683
+ contact_user_external_id = \
684
+ self.contact_user_external.insert_contact_and_link_to_existing_or_new_user_external(
685
+ contact_dict=contact_dict,
686
+ contact_email_address_str=contact_dict["email1"],
687
+ contact_id=contact_id,
688
+ system_id=contact_dict.get("system_id"),
689
+ # TODO What happends if contact do not have email?
690
+ # TODO I'm not sure we should use contact_dict["email1"] for user_external_dict["username"] probably bug
691
+ user_external_dict={"username": contact_dict["email1"]}
692
+ )
693
+ print("After " + __name__, file=sys.stderr, flush=True)
694
+ return contact_user_external_id
660
695
 
696
+ # new
697
+ def __insert_link_contact_user_external_by_contact_dict_and_user_external_dict(
698
+ self,
699
+ contact_dict: dict,
700
+ user_external_dict: dict) -> int:
701
+ print("Before2 " + __name__, file=sys.stderr, flush=True)
702
+ contact_user_external_id = \
703
+ self.contact_user_external.insert_contact_and_link_to_existing_or_new_user_external(
704
+ contact_dict=contact_dict,
705
+ contact_email_address_str=contact_dict["email1"],
706
+ contact_id=contact_dict["contact_id"],
707
+ system_id=contact_dict.get("system_id"),
708
+ user_external_dict=user_external_dict
709
+ )
710
+ print("After2 " + __name__, file=sys.stderr, flush=True)
661
711
  return contact_user_external_id
662
712
 
663
713
  def __insert_contact_profiles(self, contact_dict: dict) -> dict:
664
- insert_information = self.contact_profiles.insert_and_link_contact_profile(
665
- contact_dict=contact_dict
666
- )
667
-
714
+ insert_information = \
715
+ self.contact_profiles.insert_and_link_contact_profile(
716
+ contact_dict=contact_dict
717
+ )
668
718
  return insert_information
669
719
 
670
720
  def __insert_link_contact_domains(self, contact_dict: dict) -> list[dict]:
@@ -906,10 +956,13 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
906
956
  view_table_name="profile_user_external_view", data_dict=profile_user_external_data_dict,
907
957
  data_dict_compare=profile_user_external_data_dict
908
958
  )
959
+ if (profile_user_external_id is None):
960
+ self.logger.error("Couldn't insert profile_user_external_id in profile_user_external_table.")
961
+ raise Exception("Couldn't insert profile_user_external_id in profile_user_external_table.")
909
962
 
910
963
  return user_external_id
911
964
 
912
- # Move this method to DataSourceInstancesLocal in data-source-instance-local-python-package
965
+ # Move this method to DataSourceInstancesLocal in data-source-instance-local-python-package
913
966
  def __get_data_source_instance_id(self, data_source_type_id: int, csv_file_path: str, user_external_id: int,
914
967
  file_name: str,
915
968
  user_external_username: str, start_index: int, end_index: int) -> int:
@@ -937,11 +990,12 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
937
990
  # TODO Move this function to python-sdk
938
991
  def detect_encoding(file_path: str, data_source_type_id: int = None):
939
992
  if data_source_type_id in [16, 17, 18]:
940
- return "utf-8"
993
+ detect_encodinfg_result = "utf-8"
941
994
  else:
942
995
  with open(file_path, 'rb') as f:
943
996
  result = chardet.detect(f.read())
944
- return result['encoding']
997
+ detect_encodinfg_result = result['encoding']
998
+ return detect_encodinfg_result
945
999
 
946
1000
  @staticmethod
947
1001
  def fix_contact_dict_by_data_source_type(contact_dict: dict) -> dict:
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.4
2
+ Name: contact-person-profile-csv-imp-local
3
+ Version: 0.0.46
4
+ Summary: PyPI Package for Circles CSVToContactPersonProfile-local Local/Remote Python
5
+ Home-page: https://github.com/circles-zone/contact-person-profile-csv-imp-local-python-package
6
+ Author: Circles
7
+ Author-email: info@circles.ai
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: contact-local>=0.0.48
12
+ Requires-Dist: logger-local>=0.0.135
13
+ Requires-Dist: database-mysql-local>=0.0.290
14
+ Requires-Dist: user-context-remote>=0.0.77
15
+ Requires-Dist: contact-email-address-local>=0.0.8
16
+ Requires-Dist: contact-group-local>=0.0.68
17
+ Requires-Dist: contact-location-local>=0.0.14
18
+ Requires-Dist: contact-notes-local>=0.0.33
19
+ Requires-Dist: contact-persons-local>=0.0.8
20
+ Requires-Dist: contact-phone-local>=0.0.12
21
+ Requires-Dist: contact-profile-local>=0.0.7
22
+ Requires-Dist: contact-user-external-local>=0.0.13
23
+ Requires-Dist: importer-local>=0.0.54
24
+ Requires-Dist: internet-domain-local>=0.0.8
25
+ Requires-Dist: location-local>=0.0.104
26
+ Requires-Dist: organization-profile-local>=0.0.4
27
+ Requires-Dist: organizations-local>=0.0.14
28
+ Requires-Dist: python-sdk-remote>=0.0.93
29
+ Requires-Dist: url-remote>=0.0.91
30
+ Requires-Dist: user-external-local>=0.0.114
31
+ Requires-Dist: chardet>=5.2.0
32
+ Dynamic: author
33
+ Dynamic: author-email
34
+ Dynamic: classifier
35
+ Dynamic: description
36
+ Dynamic: description-content-type
37
+ Dynamic: home-page
38
+ Dynamic: requires-dist
39
+ Dynamic: summary
40
+
41
+ This is a package for sharing common XXX function used in different repositories
@@ -0,0 +1,7 @@
1
+ contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=HMZaoJTFg-PCg8Nc_hRm1iBikkLm67yxLFNMr-NXOFk,55492
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=SsMFKnI7y3P_kQxH21rxKnX7H4MZlemBy5vuv_Ns_a4,1180
4
+ contact_person_profile_csv_imp_local-0.0.46.dist-info/METADATA,sha256=ttYH12F5UlYj_QIHk12BQO2pXajxKereykJLZanuv7w,1585
5
+ contact_person_profile_csv_imp_local-0.0.46.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
6
+ contact_person_profile_csv_imp_local-0.0.46.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
+ contact_person_profile_csv_imp_local-0.0.46.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.1.0)
2
+ Generator: setuptools (80.4.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,34 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.45
4
- Summary: PyPI Package for Circles CSVToContactPersonProfile-local Local/Remote Python
5
- Home-page: https://github.com/circles-zone/contact-person-profile-csv-imp-local-python-package
6
- Author: Circles
7
- Author-email: info@circles.ai
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: Other/Proprietary License
10
- Classifier: Operating System :: OS Independent
11
- Description-Content-Type: text/markdown
12
- Requires-Dist: contact-local >=0.0.48
13
- Requires-Dist: logger-local >=0.0.135
14
- Requires-Dist: database-mysql-local >=0.0.290
15
- Requires-Dist: user-context-remote >=0.0.77
16
- Requires-Dist: contact-email-address-local >=0.0.8
17
- Requires-Dist: contact-group-local >=0.0.68
18
- Requires-Dist: contact-location-local >=0.0.14
19
- Requires-Dist: contact-notes-local >=0.0.33
20
- Requires-Dist: contact-persons-local >=0.0.8
21
- Requires-Dist: contact-phone-local >=0.0.12
22
- Requires-Dist: contact-profile-local >=0.0.7
23
- Requires-Dist: contact-user-external-local >=0.0.1
24
- Requires-Dist: importer-local >=0.0.54
25
- Requires-Dist: internet-domain-local >=0.0.8
26
- Requires-Dist: location-local >=0.0.104
27
- Requires-Dist: organization-profile-local >=0.0.4
28
- Requires-Dist: organizations-local >=0.0.14
29
- Requires-Dist: python-sdk-remote >=0.0.93
30
- Requires-Dist: url-remote >=0.0.91
31
- Requires-Dist: user-external-local >=0.0.42
32
- Requires-Dist: chardet >=5.2.0
33
-
34
- This is a package for sharing common XXX function used in different repositories
@@ -1,7 +0,0 @@
1
- contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=eRkMHtfPCNHnQoYrpS_dT8e7jQdduutBmsf8ycdbzCU,53218
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=SsMFKnI7y3P_kQxH21rxKnX7H4MZlemBy5vuv_Ns_a4,1180
4
- contact_person_profile_csv_imp_local-0.0.45.dist-info/METADATA,sha256=cCUCBodDpam4EL5oOu9rbA4nMY4o7vihO7YtHLsy9BQ,1481
5
- contact_person_profile_csv_imp_local-0.0.45.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
6
- contact_person_profile_csv_imp_local-0.0.45.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
- contact_person_profile_csv_imp_local-0.0.45.dist-info/RECORD,,