contact-person-profile-csv-imp-local 0.0.27__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.
- contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py +40 -8
- {contact_person_profile_csv_imp_local-0.0.27.dist-info → contact_person_profile_csv_imp_local-0.0.29.dist-info}/METADATA +1 -1
- {contact_person_profile_csv_imp_local-0.0.27.dist-info → contact_person_profile_csv_imp_local-0.0.29.dist-info}/RECORD +5 -5
- {contact_person_profile_csv_imp_local-0.0.27.dist-info → contact_person_profile_csv_imp_local-0.0.29.dist-info}/WHEEL +0 -0
- {contact_person_profile_csv_imp_local-0.0.27.dist-info → contact_person_profile_csv_imp_local-0.0.29.dist-info}/top_level.txt +0 -0
|
@@ -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',
|
|
@@ -280,6 +285,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
280
285
|
# TODO We should take care of situation which the contact already exists and we need to update it
|
|
281
286
|
contact_dict["data_source_instance_id"] = data_source_instance_id
|
|
282
287
|
contact_dict["source"] = "Import"
|
|
288
|
+
contact_dict["owner_profile_id"] = self.user_context.get_effective_profile_id()
|
|
283
289
|
contact_id = self.contacts_local.upsert_contact_dict(contact_dict=contact_dict)
|
|
284
290
|
contact_dict["contact_id"] = contact_id
|
|
285
291
|
if contact_id:
|
|
@@ -301,6 +307,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
301
307
|
# TODO Use regex to extract the data from the URL
|
|
302
308
|
# TODO add to user_external using user-external-python-package
|
|
303
309
|
|
|
310
|
+
# TODO This looks like a generic method, please move it to url-remote-python-package
|
|
304
311
|
@staticmethod
|
|
305
312
|
def process_url(original_url: str) -> str:
|
|
306
313
|
prefixes = ['http://', 'https://'] # noqa
|
|
@@ -315,6 +322,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
315
322
|
|
|
316
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
|
|
317
324
|
|
|
325
|
+
# TODO Please change ALL methods which are not public to become private
|
|
318
326
|
def process_notes(self, contact_note: str) -> None:
|
|
319
327
|
# TODO number_of_system_recommednded_groups_identified_in_contact_notes = get_system_recommended_groups_from_contact_notes( contact_notes: str)
|
|
320
328
|
|
|
@@ -332,6 +340,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
332
340
|
|
|
333
341
|
pass
|
|
334
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
|
|
335
347
|
def get_location_type_id_by_name(self, location_type_name: str) -> int or None:
|
|
336
348
|
"""
|
|
337
349
|
Get the location type ID by its name
|
|
@@ -343,6 +355,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
343
355
|
select_clause_value="location_type_id", column_name="title", column_value=location_type_name)
|
|
344
356
|
return location_type_id
|
|
345
357
|
|
|
358
|
+
# TODO Move this method to ContactsLocal class in contact-local
|
|
359
|
+
# This method is being used by import-csv-contact
|
|
346
360
|
def __insert_contact_details_to_db(self, *, contact_dict: dict, user_external_id: int,
|
|
347
361
|
data_source_instance_id: int, data_source_type_id: int) -> int:
|
|
348
362
|
|
|
@@ -351,7 +365,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
351
365
|
|
|
352
366
|
# insert link contact_location
|
|
353
367
|
# The location is in contact_dict
|
|
368
|
+
# TODO Can we have a better name for locations_results? Maybe contact_locations?
|
|
354
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
|
|
355
372
|
contact_dict["location_id"] = location_results[0].get("location_id")
|
|
356
373
|
contact_dict["country_id"] = location_results[0].get("country_id")
|
|
357
374
|
|
|
@@ -395,6 +412,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
395
412
|
)
|
|
396
413
|
return importer_id
|
|
397
414
|
|
|
415
|
+
# TODO Move this method to LocationsLocal
|
|
416
|
+
# This method is being used by import-csv-contact
|
|
398
417
|
def __insert_organization(self, contact_dict: dict) -> int or None:
|
|
399
418
|
|
|
400
419
|
if not contact_dict.get("organization"):
|
|
@@ -439,6 +458,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
439
458
|
|
|
440
459
|
return organization_dict
|
|
441
460
|
|
|
461
|
+
# TODO When do we use it? Multiple profiles to one organization?
|
|
442
462
|
def __insert_organization_profile(self, organization_id: int, profiles_ids_list: list[int]) -> list[int] or None:
|
|
443
463
|
|
|
444
464
|
if not organization_id or not profiles_ids_list:
|
|
@@ -461,6 +481,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
461
481
|
_groups = contact_dict.get("groups").split(", ")
|
|
462
482
|
for group in _groups:
|
|
463
483
|
groups.append(group)
|
|
484
|
+
for group in self.groups_list:
|
|
485
|
+
groups.append(group)
|
|
464
486
|
if len(groups) > 0:
|
|
465
487
|
groups_linked = self.contact_groups.insert_link_contact_group_with_group_local(
|
|
466
488
|
contact_id=contact_id, groups_names=groups)
|
|
@@ -567,12 +589,15 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
567
589
|
location_dicts = self.__procces_location_of_contact(contact_dict)
|
|
568
590
|
if not location_dicts:
|
|
569
591
|
return
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
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
|
|
576
601
|
def __insert_importer(self, contact_id: int, location_id: int, user_external_id: int,
|
|
577
602
|
data_source_type_id: int, data_source_instance_id: int) -> int:
|
|
578
603
|
# TODO: Shall we consider the url of csv's as the following? Use Sql2Code. Use const enum
|
|
@@ -582,7 +607,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
582
607
|
url = "www.outlook.com"
|
|
583
608
|
elif data_source_type_id == 18:
|
|
584
609
|
url = "www.linkedin.com"
|
|
585
|
-
|
|
610
|
+
# TODO Please change all Magic Numbers to data generated by Sql2Code
|
|
611
|
+
elif data_source_type_id == 57: # BGU Course csv
|
|
586
612
|
url = None
|
|
587
613
|
else:
|
|
588
614
|
raise ValueError("data_source_type_id is not valid")
|
|
@@ -597,6 +623,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
597
623
|
|
|
598
624
|
return importer_id
|
|
599
625
|
|
|
626
|
+
# TODO Move this method to ContactsLocal if not exists already
|
|
600
627
|
def __procces_location_of_contact(self, contact_dict: dict) -> dict or None:
|
|
601
628
|
"""
|
|
602
629
|
Process location of Google contact
|
|
@@ -688,6 +715,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
688
715
|
return proccessed_location_dicts
|
|
689
716
|
|
|
690
717
|
@staticmethod
|
|
718
|
+
# TODO Move this method to LocationsLocal if not exists already
|
|
691
719
|
def __create_location_dict(*, address_street: str, address_city: str, address_postal_code: str,
|
|
692
720
|
address_country: str, address_state: str) -> dict:
|
|
693
721
|
location_dict = {
|
|
@@ -705,12 +733,14 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
705
733
|
return location_dict
|
|
706
734
|
|
|
707
735
|
@staticmethod
|
|
736
|
+
# Move this method to ContactsLocal if not exists already
|
|
708
737
|
def __get_phone_numbers_list(contact_dict: dict) -> list:
|
|
709
738
|
phones_list = [contact_dict.get(f"phone{i}")
|
|
710
739
|
for i in range(1, 4) if contact_dict.get(f"phone{i}")]
|
|
711
740
|
return phones_list
|
|
712
741
|
|
|
713
742
|
@staticmethod
|
|
743
|
+
# Move this method to ContactsLocal if not exists already
|
|
714
744
|
def __get_email_addresses_list(contact_dict: dict) -> list:
|
|
715
745
|
emails_list = [contact_dict.get(f"email{i}")
|
|
716
746
|
for i in range(1, 4) if contact_dict.get(f"email{i}")]
|
|
@@ -735,6 +765,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
735
765
|
|
|
736
766
|
return user_external_id
|
|
737
767
|
|
|
768
|
+
# Move this method to DataSourceInstancesLocal in data-source-instance-local-python-package
|
|
738
769
|
def __get_data_source_instance_id(self, data_source_type_id: int, csv_file_path: str, user_external_id: int,
|
|
739
770
|
file_name: str,
|
|
740
771
|
user_external_username: str, start_index: int, end_index: int) -> int:
|
|
@@ -759,6 +790,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
|
|
|
759
790
|
return data_source_instance_id
|
|
760
791
|
|
|
761
792
|
@staticmethod
|
|
793
|
+
# TODO Move this function to python-sdk
|
|
762
794
|
def detect_encoding(file_path: str, data_source_type_id: int = None):
|
|
763
795
|
if data_source_type_id == 16 or data_source_type_id == 17 or data_source_type_id == 18:
|
|
764
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.
|
|
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=
|
|
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.
|
|
5
|
-
contact_person_profile_csv_imp_local-0.0.
|
|
6
|
-
contact_person_profile_csv_imp_local-0.0.
|
|
7
|
-
contact_person_profile_csv_imp_local-0.0.
|
|
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,,
|
|
File without changes
|