contact-person-profile-csv-imp-local 0.0.26__py3-none-any.whl → 0.0.28__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 @@ import csv
2
2
  import os
3
3
  from datetime import datetime
4
4
  from zoneinfo import ZoneInfo
5
+ import chardet
5
6
 
6
7
  from .contact_person_profile_csv_imp_local_constants import CSVToContactPersonProfileConstants
7
8
  from data_source_local.data_source import DataSources
@@ -185,7 +186,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
185
186
  contact_fields_to_keep = (
186
187
  'name_prefix', 'additional_name', 'name_suffix', 'nickname', 'full_name', 'title', 'department', 'notes',
187
188
  'first_name', 'last_name', 'phone1', 'phone2', 'phone3', 'birthday', 'email1', 'email2', 'email3',
188
- 'hashtag', 'url',
189
+ 'hashtag', 'url', 'groups',
189
190
  'website1', 'handle', 'address1_street', 'address1_city', 'address1_state', 'address1_postal_code',
190
191
  'address1_country', 'address2_street', 'address2_city', 'address2_state', 'address2_postal_code',
191
192
  'address2_country', 'job_title', 'organization', 'display_as')
@@ -201,8 +202,9 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
201
202
  fields_dictonary = self.data_sources.get_fields_name_from_csv(data_source_type_id)
202
203
  keys = list(fields_dictonary.keys())
203
204
  contact_data_by_contact_id_dict = {}
205
+ encoding = CSVToContactPersonProfile.detect_encoding(file_path=csv_file_path, data_source_type_id=data_source_type_id)
204
206
  # TODO: break this into smaller functions
205
- with (open(csv_file_path, 'r', encoding='utf-8') as csv_file):
207
+ with (open(csv_file_path, 'r', encoding=encoding) as csv_file):
206
208
  for row_index, row in enumerate(csv.DictReader(csv_file)):
207
209
  if end_index is not None and not start_index <= row_index <= end_index:
208
210
  continue
@@ -278,6 +280,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
278
280
  # TODO We should take care of situation which the contact already exists and we need to update it
279
281
  contact_dict["data_source_instance_id"] = data_source_instance_id
280
282
  contact_dict["source"] = "Import"
283
+ contact_dict["owner_profile_id"] = self.user_context.get_effective_profile_id()
281
284
  contact_id = self.contacts_local.upsert_contact_dict(contact_dict=contact_dict)
282
285
  contact_dict["contact_id"] = contact_id
283
286
  if contact_id:
@@ -455,6 +458,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
455
458
  groups.append(contact_dict.get("organization"))
456
459
  if contact_dict.get("job_title"):
457
460
  groups.append(contact_dict.get("job_title"))
461
+ if contact_dict.get("groups"):
462
+ _groups = contact_dict.get("groups").split(", ")
463
+ for group in _groups:
464
+ groups.append(group)
458
465
  if len(groups) > 0:
459
466
  groups_linked = self.contact_groups.insert_link_contact_group_with_group_local(
460
467
  contact_id=contact_id, groups_names=groups)
@@ -548,6 +555,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
548
555
  domain_insert_information_list.append(domain_insert_information)
549
556
  website_count += 1
550
557
  website_url = contact_dict.get("website" + str(website_count))
558
+ url = contact_dict.get("url")
559
+ if url:
560
+ domain_insert_information = self.domain_local.link_contact_to_domain(
561
+ contact_id=contact_id, url=url)
562
+ domain_insert_information_list.append(domain_insert_information)
551
563
 
552
564
  return domain_insert_information_list
553
565
 
@@ -571,6 +583,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
571
583
  url = "www.outlook.com"
572
584
  elif data_source_type_id == 18:
573
585
  url = "www.linkedin.com"
586
+ elif data_source_type_id == 57:
587
+ url = None
574
588
  else:
575
589
  raise ValueError("data_source_type_id is not valid")
576
590
  importer_id = self.importers_local.insert(
@@ -744,3 +758,12 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
744
758
  }
745
759
  )
746
760
  return data_source_instance_id
761
+
762
+ @staticmethod
763
+ def detect_encoding(file_path: str, data_source_type_id: int = None):
764
+ if data_source_type_id == 16 or data_source_type_id == 17 or data_source_type_id == 18:
765
+ return "utf-8"
766
+ else:
767
+ with open(file_path, 'rb') as f:
768
+ result = chardet.detect(f.read())
769
+ return result['encoding']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.26
3
+ Version: 0.0.28
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
@@ -29,5 +29,6 @@ Requires-Dist: organizations-local >=0.0.14
29
29
  Requires-Dist: python-sdk-remote >=0.0.93
30
30
  Requires-Dist: url-remote >=0.0.91
31
31
  Requires-Dist: user-external-local >=0.0.42
32
+ Requires-Dist: chardet >=5.2.0
32
33
 
33
34
  This is a package for sharing common XXX function used in different repositories
@@ -1,7 +1,7 @@
1
- contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=kcCL27j1965-iRYTBdkYMiLG6-epO1-lnutxQxseXl0,40355
1
+ contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=KlaCY4YDlMu77bZLF7sIXHiYLfiDu7scds_CyS4ugMc,41462
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.26.dist-info/METADATA,sha256=Anapud81s7tqkNoBP4UvAs6Fnrv_H8YDEg2HdkLhn4Q,1450
5
- contact_person_profile_csv_imp_local-0.0.26.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- contact_person_profile_csv_imp_local-0.0.26.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
- contact_person_profile_csv_imp_local-0.0.26.dist-info/RECORD,,
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,,