contact-person-profile-csv-imp-local 0.0.18__py3-none-any.whl → 0.0.21__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,40 +1,36 @@
1
1
  import csv
2
- import sys
3
2
  import os
4
-
5
3
  from datetime import datetime
6
4
  from zoneinfo import ZoneInfo
7
5
 
8
- from dotenv import load_dotenv
9
- load_dotenv()
10
- script_directory = os.path.dirname(os.path.abspath(__file__))
11
- sys.path.append(os.path.join(script_directory, '..'))
12
-
13
- from contact_email_address_local.contact_email_addresses_local import ContactEmailAdressesLocal
14
- from contact_group_local.contact_group import ContactGroups
15
- from contact_local.contact_local import ContactsLocal
16
- from contact_location_local.contact_location_local import ContactLocationLocal
17
- from contact_notes_local.contact_notes_local import ContactNotesLocal
18
- from contact_persons_local.contact_persons_local import ContactPersonsLocal
19
- from contact_phone_local.contact_phone_local import ContactPhoneLocal
20
- from contact_profile_local.contact_profiles_local import ContactProfilesLocal
21
- from contact_user_external_local.contact_user_external_local import ContactUserExternalLocal
22
- from database_mysql_local.generic_crud import GenericCRUD
23
- from database_mysql_local.point import Point
24
- from importer_local.ImportersLocal import ImportersLocal
25
- from internet_domain_local.internet_domain_local import DomainLocal
26
- from location_local.country import Country
27
- from location_local.location_local_constants import LocationLocalConstants
28
- from logger_local.MetaLogger import MetaLogger
29
- from organization_profile_local.organization_profiles_local import OrganizationProfilesLocal
6
+ from .contact_person_profile_csv_imp_local_constants import CSVToContactPersonProfileConstants
7
+ from data_source_local.data_source import DataSources
8
+ # from user_external_local.user_externals_local import UserExternalsLocal
9
+ # from user_context_remote.user_context import UserContext
30
10
  from organizations_local.organizations_local import OrganizationsLocal
11
+ from organization_profile_local.organization_profiles_local import OrganizationProfilesLocal
12
+ from logger_local.MetaLogger import MetaLogger
13
+ from location_local.location_local_constants import LocationLocalConstants
14
+ from location_local.country import Country
15
+ from internet_domain_local.internet_domain_local import DomainLocal
16
+ from importer_local.ImportersLocal import ImportersLocal
17
+ from database_mysql_local.point import Point
18
+ from database_mysql_local.generic_crud import GenericCRUD
19
+ from contact_user_external_local.contact_user_external_local import ContactUserExternalLocal
20
+ from contact_profile_local.contact_profiles_local import ContactProfilesLocal
21
+ from contact_phone_local.contact_phone_local import ContactPhoneLocal
22
+ from phones_local.phones_local import PhonesLocal
23
+ from contact_persons_local.contact_persons_local import ContactPersonsLocal
24
+ from contact_notes_local.contact_notes_local import ContactNotesLocal
25
+ from contact_location_local.contact_location_local import ContactLocationLocal
26
+ from contact_local.contact_local import ContactsLocal
27
+ from contact_group_local.contact_group import ContactGroups
28
+ from contact_email_address_local.contact_email_addresses_local import ContactEmailAdressesLocal
29
+
31
30
  # import pycountry
32
31
  from phonenumbers import NumberParseException
33
32
  from user_context_remote.user_context import UserContext
34
33
  from user_external_local.user_externals_local import UserExternalsLocal
35
- from data_source_local.data_source import DataSources
36
-
37
- from .contact_person_profile_csv_imp_local_constants import CSVToContactPersonProfileConstants
38
34
 
39
35
  # from contact_local.contact_local import ContactsLocal
40
36
  # from database_mysql_local.generic_crud import GenericCRUD
@@ -110,7 +106,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
110
106
  GenericCRUD.__init__(self, default_schema_name="field", default_column_name="field_id",
111
107
  default_table_name="field_table", default_view_table_name="field_view",
112
108
  is_test_data=is_test_data)
113
- self.contact_entity_type_id = self.select_one_value_by_id(
109
+ self.contact_entity_type_id = self.select_one_value_by_column_and_value(
114
110
  schema_name="entity_type", view_table_name="entity_type_ml_en_view",
115
111
  select_clause_value="entity_type_id", column_name="title", column_value="Contact")
116
112
  self.user_context = UserContext()
@@ -137,25 +133,25 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
137
133
  # :param data_source_type_id: The data source ID
138
134
  # :return: The field name
139
135
  # """
140
- #
136
+ #
141
137
  # 'data_source_type_id': data_source_type_id})
142
138
 
143
139
  # self.set_schema(schema_name="data_source_field")
144
- # data_source_field_tuples = self.select_multi_tuple_by_where(view_table_name="data_source_field_view",
145
- # select_clause_value="external_field_name",
146
- # where="data_source_type_id = %s AND field_id = %s",
147
- # params=(data_source_type_id, field_id))
140
+ # data_source_field_tuples = self.select_multi_tuple_by_where(view_table_name="data_source_field_view",
141
+ # select_clause_value="external_field_name",
142
+ # where="data_source_type_id = %s AND field_id = %s",
143
+ # params=(data_source_type_id, field_id))
148
144
 
149
145
  # if data_source_field_tuples:
150
- #
146
+ #
151
147
  # return data_source_field_tuples[0][0]
152
148
  # return
153
149
 
154
150
  # TODO what are the diff between csv_path and directory_name?
155
- # ans: csv_path is the full path to the csv file, directory_name is the directory where the csv file is located
151
+ # ans: csv_path is the full path to the csv file, directory_name is the directory where the csv file is located
156
152
 
157
153
  # TODO I think file name should be after directory_name and csv_path
158
- # ans: it cannot be after directory_name and csv_path because it is a required parameter
154
+ # ans: it cannot be after directory_name and csv_path because it is a required parameter
159
155
 
160
156
  # TODO: break this function into smaller functions
161
157
  def insert_update_contact_from_csv(
@@ -176,8 +172,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
176
172
 
177
173
  # TODO Please explain
178
174
  # if csv_path is provided then we will use the full path
179
- # if csv_path is not provided then we will use the directory_name and file_name to create the full path
180
- # if directory_name is not provided the assumption is that the file is in the same directory as the script and not in a folder
175
+ # if csv_path is not provided then we will use the directory_name and file_name to create the full path
176
+ # if directory_name is not provided the assumption is that the file is in the same directory as the script and not in a folder
181
177
  if csv_path is not None:
182
178
  csv_file_path = csv_path
183
179
  else:
@@ -198,7 +194,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
198
194
  # We create a new data_source_instance_id everytime we import a new csv file
199
195
  data_source_instance_id = self.__get_data_source_instance_id(
200
196
  data_source_type_id=data_source_type_id, csv_file_path=csv_file_path,
201
- user_external_id=user_external_id, file_name=file_name,
197
+ user_external_id=user_external_id, file_name=file_name,
202
198
  user_external_username=user_external_username,
203
199
  start_index=start_index, end_index=end_index
204
200
  )
@@ -211,16 +207,16 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
211
207
  if end_index is not None and not start_index <= row_index <= end_index:
212
208
  continue
213
209
  csv_keys = list(row.keys())
214
- contact_data = {}
210
+ contact_dict = {}
215
211
  '''
216
212
  # Old version
217
213
  for fields in keys:
218
214
  if fields_dictonary[fields] not in csv_keys:
219
215
  continue
220
216
  if fields_dictonary[fields] is not None and isinstance(fields_dictonary[fields], str):
221
- contact_data[fields] = row[fields_dictonary[fields]]
217
+ contact_dict[fields] = row[fields_dictonary[fields]]
222
218
  else:
223
- contact_data[fields] = None
219
+ contact_dict[fields] = None
224
220
  '''
225
221
  splitter = ' ::: '
226
222
  for field in keys:
@@ -233,77 +229,78 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
233
229
  values_list = row[field_value].split(splitter)
234
230
  for index, value in enumerate(values_list):
235
231
  current_field = field.replace('1', str(index + 1))
236
- if not contact_data.get(current_field):
237
- contact_data[current_field] = value
238
- elif not contact_data.get(field):
239
- contact_data[field] = row[field_value]
232
+ if not contact_dict.get(current_field):
233
+ contact_dict[current_field] = value
234
+ elif not contact_dict.get(field):
235
+ contact_dict[field] = row[field_value]
240
236
  else:
241
- contact_data[field] = None
237
+ contact_dict[field] = None
242
238
 
243
- contact_data = {key: contact_data.get(key) or None for key in contact_fields_to_keep}
244
- if (not contact_data.get('first_name')
245
- and not contact_data.get('last_name')
246
- and not contact_data.get('organization')):
239
+ contact_dict = {key: contact_dict.get(
240
+ key) or None for key in contact_fields_to_keep}
241
+ if (not contact_dict.get('first_name')
242
+ and not contact_dict.get('last_name')
243
+ and not contact_dict.get('organization')):
247
244
  continue
248
- contact_data['is_test_data'] = self.is_test_data
245
+ contact_dict['is_test_data'] = self.is_test_data
249
246
 
250
247
  # TODO Please call get_display_name(first_name, last_name, organization) if display_as is empty
251
248
 
252
249
  # for phone in ['phone1', 'phone2', 'phone3']:
253
- # if contact_data[phone] is None:
250
+ # if contact_dict[phone] is None:
254
251
  # continue
255
- # phone_data = process_phone(original_phone_number=contact_data[phone])
252
+ # phone_data = process_phone(original_phone_number=contact_dict[phone])
256
253
  # if phone_data is None:
257
254
  # continue
258
255
  # else:
259
- # contact_data[phone] = phone_data['normalized_phone_number']
256
+ # contact_dict[phone] = phone_data['normalized_phone_number']
260
257
 
261
- # contact_data['first_name'] = process_first_name(
262
- # original_first_name=contact_data['first_name'])
263
- # contact_data['last_name'] = process_last_name(
264
- # original_last_name=contact_data['last_name'])
258
+ # contact_dict['first_name'] = process_first_name(
259
+ # original_first_name=contact_dict['first_name'])
260
+ # contact_dict['last_name'] = process_last_name(
261
+ # original_last_name=contact_dict['last_name'])
265
262
 
266
263
  # TODO This should be executed also by Google Contact Sync (please make sure it is in people-local-python-package
267
264
  # i.e. get_display_name(first_name, last_name, organization) -> str
268
- if contact_data.get('display_as') is None:
269
- contact_data['display_as'] = contact_data.get('first_name') or "" # prevent None
270
- if (contact_data.get('last_name')
271
- and not contact_data.get('last_name').isdigit()):
272
- contact_data['display_as'] += " " + contact_data['last_name']
273
- if not contact_data['display_as'] and contact_data.get('organization'):
274
- contact_data['display_as'] += " " + contact_data['organization']
265
+ if contact_dict.get('display_as') is None:
266
+ contact_dict['display_as'] = contact_dict.get(
267
+ 'first_name') or "" # prevent None
268
+ if (contact_dict.get('last_name')
269
+ and not contact_dict.get('last_name').isdigit()):
270
+ contact_dict['display_as'] += " " + contact_dict['last_name']
271
+ if not contact_dict['display_as'] and contact_dict.get('organization'):
272
+ contact_dict['display_as'] += " " + contact_dict['organization']
275
273
 
276
- # TODO if contact_data['display_as'] still empty raise?
274
+ # TODO if contact_dict['display_as'] still empty raise?
277
275
 
278
- # TODO process_notes( contact_data[notes] )
276
+ # TODO process_notes( contact_dict[notes] )
279
277
 
280
278
  # TODO We should take care of situation which the contact already exists and we need to update it
281
- contact_data["data_source_instance_id"] = data_source_instance_id
282
- contact_data["source"] = "Import"
283
- contact_id = self.contacts_local.upsert_contact_dict(contact_dict=contact_data)
279
+ contact_dict["data_source_instance_id"] = data_source_instance_id
280
+ contact_dict["source"] = "Import"
281
+ contact_id = self.contacts_local.upsert_contact_dict(contact_dict=contact_dict)
284
282
  if contact_id:
285
283
  self.__insert_contact_details_to_db(
286
- contact_id=contact_id, contact_dict=contact_data, user_external_id=user_external_id,
284
+ contact_id=contact_id, contact_dict=contact_dict, user_external_id=user_external_id,
287
285
  data_source_instance_id=data_source_instance_id,
288
286
  data_source_type_id=data_source_type_id)
289
- contact_data_by_contact_id_dict[contact_id] = contact_data
290
- # groups_linked_by_job_title = process_job_title(contact_id=contact_id, job_title=contact_data['job_title'])
287
+ contact_data_by_contact_id_dict[contact_id] = contact_dict
288
+ # groups_linked_by_job_title = process_job_title(contact_id=contact_id, job_title=contact_dict['job_title'])
291
289
  # if groups_linked_by_job_title is None:
292
290
  # logger.info("No groups linked by job title to contact " + str(contact_id))
293
291
 
294
-
295
292
  return contact_data_by_contact_id_dict
296
293
 
297
-
298
294
  # TODO def insert_update_contact_groups_from_contact_notes( contact_notes: str) -> int:
299
295
  # TODO Add contact_group with seq, attribute, is_sure using group-local-python-package
300
296
 
301
297
  # TODO def process_people_url( people_url ) -> str:
302
298
  # TODO Use regex to extract the data from the URL
303
299
  # TODO add to user_external using user-external-python-package
300
+
304
301
  @staticmethod
305
302
  def process_url(original_url: str) -> str:
306
- prefixes = ['http://', 'https://']
303
+ prefixes = ['http://', 'https://'] # noqa
307
304
  for prefix in prefixes:
308
305
  if original_url.startswith(prefix):
309
306
  original_url = original_url[len(prefix):]
@@ -313,7 +310,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
313
310
 
314
311
  return original_url
315
312
 
316
- # 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
313
+ # 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
314
 
318
315
  def process_notes(self, contact_note: str) -> None:
319
316
  # TODO number_of_system_recommednded_groups_identified_in_contact_notes = get_system_recommended_groups_from_contact_notes( contact_notes: str)
@@ -338,14 +335,14 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
338
335
  :param location_type_name: The location type name
339
336
  :return: The location type ID
340
337
  """
341
- location_type_id = self.select_one_value_by_id(
338
+ location_type_id = self.select_one_value_by_column_and_value(
342
339
  schema_name="location", view_table_name="location_type_ml_view",
343
340
  select_clause_value="location_type_id", column_name="title", column_value=location_type_name)
344
341
  return location_type_id
345
342
 
346
- def __insert_contact_details_to_db(self, contact_id: int, contact_dict: dict, user_external_id: int,
343
+ def __insert_contact_details_to_db(self, *, contact_id: int, contact_dict: dict, user_external_id: int,
347
344
  data_source_instance_id: int, data_source_type_id: int) -> int:
348
-
345
+
349
346
  location_id = DEFAULT_LOCATION_ID
350
347
  # insert organization
351
348
  organization_id = self.__insert_organization(contact_dict=contact_dict)
@@ -353,29 +350,25 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
353
350
  # insert link contact_location
354
351
  # The location is in contact_dict
355
352
  location_results = self.__insert_link_contact_location(
356
- contact_dict=contact_dict, contact_id=contact_id)
357
- if location_results:
358
- location_id = location_results[0].get(
359
- "location_id") or DEFAULT_LOCATION_ID
353
+ contact_dict=contact_dict, contact_id=contact_id) or [{}]
354
+ location_id = location_results[0].get(
355
+ "location_id") or DEFAULT_LOCATION_ID
356
+ country_id = location_results[0].get("country_id")
360
357
 
361
358
  # insert link contact_group
362
359
  self.__insert_link_contact_groups(
363
360
  contact_dict=contact_dict, contact_id=contact_id)
364
361
 
365
362
  # insert link contact_persons
366
- self.__insert_link_contact_persons(
367
- contact_dict=contact_dict, contact_id=contact_id)
363
+ contact_person_result_dict = self.__insert_link_contact_persons(
364
+ contact_dict=contact_dict, contact_id=contact_id) or {}
365
+ person_id = contact_person_result_dict.get("person_id")
368
366
 
369
367
  # insert link contact_profiles
370
- contact_profile_info = (
371
- self.__insert_contact_profiles(
372
- contact_dict=contact_dict, contact_id=contact_id)
373
- )
374
- if contact_profile_info is not None:
375
- profile_id = contact_profile_info.get(
376
- "profile_id") or DEFAULT_PROFILE_ID
377
- else:
378
- profile_id = DEFAULT_PROFILE_ID
368
+ contact_profile_info = self.__insert_contact_profiles(
369
+ contact_dict=contact_dict, contact_id=contact_id, person_id=person_id) or {}
370
+
371
+ profile_id = contact_profile_info.get("profile_id")
379
372
 
380
373
  # insert organization-profile
381
374
  self.__insert_organization_profile(
@@ -383,16 +376,16 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
383
376
 
384
377
  # insert link contact_email_addresses
385
378
  self.__insert_link_contact_email_addresses(
386
- contact_dict=contact_dict, contact_id=contact_id)
379
+ contact_dict=contact_dict, contact_id=contact_id, person_id=person_id, profile_id=profile_id)
387
380
 
388
381
  # insert link contact_notes
389
- self.__insert_link_contact_notes_and_text_blocks(contact_dict=contact_dict,
390
- contact_id=contact_id,
391
- profile_id=profile_id)
382
+ self.__insert_link_contact_notes_and_text_blocks(
383
+ contact_dict=contact_dict, contact_id=contact_id, profile_id=profile_id)
392
384
 
393
385
  # insert link contact_phones
394
386
  self.__insert_link_contact_phones(
395
- contact_dict=contact_dict, contact_id=contact_id)
387
+ contact_dict=contact_dict, contact_id=contact_id, profile_id=profile_id,
388
+ person_id=person_id, location_id=location_id, country_id=country_id)
396
389
 
397
390
  # inset link contact_user_externals
398
391
  self.__insert_link_contact_user_external(
@@ -410,9 +403,9 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
410
403
  data_source_type_id=data_source_type_id
411
404
  )
412
405
  return importer_id
413
-
406
+
414
407
  def __insert_organization(self, contact_dict: dict) -> int or None:
415
-
408
+
416
409
  if not contact_dict.get("organization"):
417
410
  return
418
411
  organization_dict = self.__create_organization_dict(
@@ -421,11 +414,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
421
414
  organization_dict=organization_dict)
422
415
  organization_id = organization_upsert_result.get("organization_id")
423
416
  organization_ml_ids_list = organization_upsert_result.get("organization_ml_ids_list") # noqa
424
-
417
+
425
418
  return organization_id
426
419
 
427
420
  def __create_organization_dict(self, organization_name: str) -> dict:
428
-
421
+
429
422
  organization_dict = {
430
423
  "is_approved": 0,
431
424
  "is_main": 1,
@@ -452,22 +445,21 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
452
445
  "is_name_approved": 0,
453
446
  "is_description_approved": 0
454
447
  }
455
-
448
+
456
449
  return organization_dict
457
450
 
458
451
  def __insert_organization_profile(self, organization_id: int, profile_id: int) -> int or None:
459
-
452
+
460
453
  if not organization_id or not profile_id:
461
-
462
- return
454
+ return None
463
455
 
464
456
  organization_profile_id = self.organization_profiles.insert_mapping_if_not_exists(
465
457
  organization_id=organization_id, profile_id=profile_id)
466
-
458
+
467
459
  return organization_profile_id
468
460
 
469
461
  def __insert_link_contact_groups(self, contact_dict: dict, contact_id: int) -> list:
470
-
462
+
471
463
  groups = []
472
464
  groups_linked = None
473
465
  if contact_dict.get("organization"):
@@ -476,23 +468,30 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
476
468
  groups.append(contact_dict.get("job_title"))
477
469
  if len(groups) > 0:
478
470
  groups_linked = self.contact_groups.insert_link_contact_group_with_group_local(
479
- contact_id=contact_id, groups=groups)
480
-
471
+ contact_id=contact_id, groups_names=groups)
472
+
481
473
  return groups_linked
482
474
 
483
- def __insert_link_contact_persons(self, contact_dict: dict, contact_id: int) -> int:
484
-
475
+ def __insert_link_contact_persons(self, contact_dict: dict, contact_id: int) -> dict:
476
+ phones_local = PhonesLocal(is_test_data=self.is_test_data)
477
+ contact_phone_number = contact_dict.get("phone1")
478
+ if contact_phone_number:
479
+ result_dict = phones_local.normalize_phone_number(original_number=contact_phone_number, region=None)
480
+ if result_dict:
481
+ contact_normalized_phone_number = result_dict.get("full_number_normalized")
482
+ else:
483
+ contact_normalized_phone_number = None
485
484
  contact_person_results_dict = self.contact_persons.insert_contact_and_link_to_existing_or_new_person(
486
485
  contact_dict=contact_dict,
487
486
  contact_email_address=contact_dict["email1"],
487
+ contact_normalized_phone_number=contact_normalized_phone_number,
488
488
  contact_id=contact_id
489
489
  )
490
- contact_person_id = contact_person_results_dict.get("contact_person_id")
491
-
492
- return contact_person_id
493
490
 
494
- def __insert_link_contact_email_addresses(self, contact_dict, contact_id) -> list[int]:
495
-
491
+ return contact_person_results_dict
492
+
493
+ def __insert_link_contact_email_addresses(self, contact_dict: dict, contact_id: int, person_id: int = None,
494
+ profile_id: int = None) -> list[int]:
496
495
  email_addresses = self.contacts_local.get_contact_email_addresses_from_contact_dict(
497
496
  contact_dict=contact_dict)
498
497
  contact_email_addresses = self.contact_email_addresses
@@ -501,10 +500,12 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
501
500
  contact_email_address_id = contact_email_addresses.insert_contact_and_link_to_email_address(
502
501
  contact_dict=contact_dict,
503
502
  contact_email_address_str=email_address,
504
- contact_id=contact_id
503
+ contact_id=contact_id,
504
+ person_id=person_id,
505
+ profile_id=profile_id
505
506
  )
506
507
  contact_email_address_ids.append(contact_email_address_id)
507
-
508
+
508
509
  return contact_email_address_ids
509
510
 
510
511
  @staticmethod
@@ -513,47 +514,59 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
513
514
  if not contact_dict.get("notes"):
514
515
  return
515
516
  # TODO: I think we should change ContactNotesLocal - send the args to the method and not the class
516
- contact_notes = ContactNotesLocal(contact_dict=contact_dict, contact_id=contact_id, profile_id=profile_id)
517
+ if profile_id is None:
518
+ # TODO: check if this method works with profile_id = None
519
+ profile_id = DEFAULT_PROFILE_ID
520
+ contact_notes = ContactNotesLocal(
521
+ contact_dict=contact_dict, contact_id=contact_id, profile_id=profile_id)
517
522
  insert_information = contact_notes.insert_contact_notes_text_block()
518
523
  contact_note_id = insert_information.get("contact_note_id")
519
524
  return contact_note_id
520
525
 
521
- def __insert_link_contact_phones(self, contact_dict: dict, contact_id: int) -> list[int]:
522
-
523
- phone_numbers = self.contacts_local.get_contact_phone_numbers_from_contact_dict(contact_dict=contact_dict)
526
+ def __insert_link_contact_phones(self, contact_dict: dict, contact_id: int, profile_id: int, person_id: int,
527
+ location_id: int, country_id: int) -> list[int]:
528
+ if location_id == DEFAULT_LOCATION_ID:
529
+ location_id = None
530
+ phone_numbers = self.contacts_local.get_contact_phone_numbers_from_contact_dict(
531
+ contact_dict=contact_dict)
524
532
  contact_phone_ids = []
525
533
  for phone_number in phone_numbers:
526
534
  contact_phone_id = self.contact_phone.insert_contact_and_link_to_existing_or_new_phone(
527
535
  contact_dict=contact_dict,
528
536
  phone_number=phone_number,
529
- contact_id=contact_id
537
+ contact_id=contact_id,
538
+ profile_id=profile_id,
539
+ person_id=person_id,
540
+ location_id=location_id,
541
+ country_id=country_id
530
542
  )
531
- contact_phone_ids.append(contact_phone_id)
532
-
543
+ contact_phone_ids.append(contact_phone_id.get("contact_phone_id"))
544
+
533
545
  return contact_phone_ids
534
546
 
535
547
  def __insert_link_contact_user_external(self, contact_dict: dict, contact_id: int) -> int:
536
-
548
+
537
549
  contact_user_external_id = self.contact_user_external.insert_contact_and_link_to_existing_or_new_user_external(
538
550
  contact_dict=contact_dict,
539
551
  contact_email_address=contact_dict["email1"],
540
552
  contact_id=contact_id,
541
553
  user_external_dict={"username": contact_dict["email1"]}
542
554
  )
543
-
555
+
544
556
  return contact_user_external_id
545
557
 
546
- def __insert_contact_profiles(self, contact_dict: dict, contact_id: int) -> dict:
547
-
558
+ def __insert_contact_profiles(self, contact_dict: dict, contact_id: int, person_id: int = None) -> dict:
559
+
548
560
  insert_information = self.contact_profiles.insert_and_link_contact_profile(
549
561
  contact_dict=contact_dict,
550
- contact_id=contact_id
562
+ contact_id=contact_id,
563
+ person_id=person_id
551
564
  )
552
-
565
+
553
566
  return insert_information
554
567
 
555
568
  def __insert_link_contact_domains(self, contact_dict: dict, contact_id: int) -> list[dict]:
556
-
569
+
557
570
  website_count = 1
558
571
  website_url = contact_dict.get("website" + str(website_count))
559
572
  domain_insert_information_list = []
@@ -563,11 +576,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
563
576
  domain_insert_information_list.append(domain_insert_information)
564
577
  website_count += 1
565
578
  website_url = contact_dict.get("website" + str(website_count))
566
-
579
+
567
580
  return domain_insert_information_list
568
581
 
569
582
  def __insert_link_contact_location(self, contact_dict: dict, contact_id: int) -> list[dict] or None:
570
-
583
+
571
584
  location_dicts = self.__procces_location_of_contact(contact_dict)
572
585
  if not location_dicts:
573
586
  return
@@ -598,7 +611,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
598
611
  user_external_id=user_external_id,
599
612
  google_people_api_resource_name=google_people_api_resource_name
600
613
  )
601
-
614
+
602
615
  return importer_id
603
616
 
604
617
  def __procces_location_of_contact(self, contact_dict: dict) -> dict or None:
@@ -607,7 +620,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
607
620
  :param contact_dict: location_dict
608
621
  :return: location_dict
609
622
  """
610
-
623
+
611
624
  address_street1 = contact_dict.get("address1_street")
612
625
  address_city1 = contact_dict.get("address1_city")
613
626
  address_state1 = contact_dict.get("address1_state")
@@ -625,9 +638,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
625
638
 
626
639
  phone_numbers_list = self.__get_phone_numbers_list(contact_dict)
627
640
  email_addresses_list = self.__get_email_addresses_list(contact_dict)
628
- if (not is_contact_location1
641
+ if (not is_contact_location1
629
642
  and not is_contact_location2
630
- and not phone_numbers_list
643
+ and not phone_numbers_list
644
+ and not phone_numbers_list
631
645
  and not email_addresses_list):
632
646
  return
633
647
  # TODO: How can we add location type?
@@ -655,11 +669,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
655
669
  country = Country.get_country_name_by_phone_number(phone_number)
656
670
  except NumberParseException as number_parse_exception:
657
671
  self.logger.error("Error while parsing phone number",
658
- object={"number_parse_exception": number_parse_exception})
672
+ object={"number_parse_exception": number_parse_exception})
659
673
  continue
660
674
  except Exception as exception:
661
675
  self.logger.error("Error while getting country name by phone number",
662
- object=exception)
676
+ object=exception)
663
677
  continue
664
678
  currect_location_dict = {
665
679
  "address_local_language": None,
@@ -687,7 +701,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
687
701
  "region": LocationLocalConstants.DEFAULT_REGION_NAME,
688
702
  }
689
703
  proccessed_location_dicts.append(currect_location_dict)
690
-
704
+
691
705
  return proccessed_location_dicts
692
706
 
693
707
  @staticmethod
@@ -704,23 +718,25 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
704
718
  "state": address_state or LocationLocalConstants.DEFAULT_STATE_NAME,
705
719
  "region": LocationLocalConstants.DEFAULT_REGION_NAME,
706
720
  }
707
-
721
+
708
722
  return location_dict
709
723
 
710
724
  @staticmethod
711
725
  def __get_phone_numbers_list(contact_dict: dict) -> list:
712
- phones_list = [contact_dict.get(f"phone{i}") for i in range(1, 4) if contact_dict.get(f"phone{i}")]
726
+ phones_list = [contact_dict.get(f"phone{i}")
727
+ for i in range(1, 4) if contact_dict.get(f"phone{i}")]
713
728
  return phones_list
714
729
 
715
730
  @staticmethod
716
731
  def __get_email_addresses_list(contact_dict: dict) -> list:
717
- emails_list = [contact_dict.get(f"email{i}") for i in range(1, 4) if contact_dict.get(f"email{i}")]
732
+ emails_list = [contact_dict.get(f"email{i}")
733
+ for i in range(1, 4) if contact_dict.get(f"email{i}")]
718
734
  # TODO use enum const for "email1" ....
719
735
  return emails_list
720
736
 
721
737
  def __get_user_external_id(self, user_external_username: str) -> int or None:
722
-
723
- user_external_id = self.user_externals_local.select_one_value_by_id(
738
+
739
+ user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
724
740
  select_clause_value="user_external_id", column_name="username",
725
741
  column_value=user_external_username, order_by="user_external_id DESC")
726
742
  if user_external_id is None:
@@ -730,17 +746,19 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
730
746
  system_id=CONTACT_PERSON_PROFILE_CSV_SYSTEM_ID,
731
747
  access_token=""
732
748
  )
733
- user_external_id = self.user_externals_local.select_one_value_by_id(
749
+ user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
734
750
  select_clause_value="user_external_id", column_name="username",
735
751
  column_value=user_external_username, order_by="user_external_id DESC")
736
752
 
737
753
  return user_external_id
738
754
 
739
- def __get_data_source_instance_id(self, data_source_type_id: int, csv_file_path: str, user_external_id: int, file_name: str,
755
+ def __get_data_source_instance_id(self, data_source_type_id: int, csv_file_path: str, user_external_id: int,
756
+ file_name: str,
740
757
  user_external_username: str, start_index: int, end_index: int) -> int:
741
758
  name = datetime.now(ZoneInfo("UTC")).strftime("%y%m%d %H%M%S") + " " + \
742
- user_external_username + " 'Google Contact- Google Contact CSV'"
743
- data_source_instance_id = self.insert(
759
+ user_external_username + " 'Google Contact- Google Contact CSV'"
760
+ # TODO: move to data_source
761
+ data_source_instance_id = super().insert(
744
762
  schema_name="data_source_instance",
745
763
  table_name="data_source_instance_table",
746
764
  data_dict={
@@ -1,7 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.18
3
+ Version: 0.0.21
4
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
5
6
  Author: Circles
6
7
  Author-email: info@circles.ai
7
8
  Classifier: Programming Language :: Python :: 3
@@ -1,7 +1,7 @@
1
- contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=5R0FOKpPvYU6-WmsCCQuIzVX_t2hCQKuFZ-OODPTfZE,40120
1
+ contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=ClFAP6ntBayUJuH-k4dgJkrml8-Wy55E4mJc3a0YHeg,41424
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.18.dist-info/METADATA,sha256=s9JiYztD5uT7ma1qqIz9NH50rkbXvj8EEObTqSP5s2I,1355
5
- contact_person_profile_csv_imp_local-0.0.18.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- contact_person_profile_csv_imp_local-0.0.18.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
- contact_person_profile_csv_imp_local-0.0.18.dist-info/RECORD,,
4
+ contact_person_profile_csv_imp_local-0.0.21.dist-info/METADATA,sha256=2yl92Bd2snQzELayCR4qIbBIMPypqqU4PvZy5EBXAUM,1450
5
+ contact_person_profile_csv_imp_local-0.0.21.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ contact_person_profile_csv_imp_local-0.0.21.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
+ contact_person_profile_csv_imp_local-0.0.21.dist-info/RECORD,,