contact-person-profile-csv-imp-local 0.0.18__py3-none-any.whl → 0.0.20__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,35 @@
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 contact_persons_local.contact_persons_local import ContactPersonsLocal
23
+ from contact_notes_local.contact_notes_local import ContactNotesLocal
24
+ from contact_location_local.contact_location_local import ContactLocationLocal
25
+ from contact_local.contact_local import ContactsLocal
26
+ from contact_group_local.contact_group import ContactGroups
27
+ from contact_email_address_local.contact_email_addresses_local import ContactEmailAdressesLocal
28
+
31
29
  # import pycountry
32
30
  from phonenumbers import NumberParseException
33
31
  from user_context_remote.user_context import UserContext
34
32
  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
33
 
39
34
  # from contact_local.contact_local import ContactsLocal
40
35
  # from database_mysql_local.generic_crud import GenericCRUD
@@ -110,7 +105,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
110
105
  GenericCRUD.__init__(self, default_schema_name="field", default_column_name="field_id",
111
106
  default_table_name="field_table", default_view_table_name="field_view",
112
107
  is_test_data=is_test_data)
113
- self.contact_entity_type_id = self.select_one_value_by_id(
108
+ self.contact_entity_type_id = self.select_one_value_by_column_and_value(
114
109
  schema_name="entity_type", view_table_name="entity_type_ml_en_view",
115
110
  select_clause_value="entity_type_id", column_name="title", column_value="Contact")
116
111
  self.user_context = UserContext()
@@ -137,25 +132,25 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
137
132
  # :param data_source_type_id: The data source ID
138
133
  # :return: The field name
139
134
  # """
140
- #
135
+ #
141
136
  # 'data_source_type_id': data_source_type_id})
142
137
 
143
138
  # 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))
139
+ # data_source_field_tuples = self.select_multi_tuple_by_where(view_table_name="data_source_field_view",
140
+ # select_clause_value="external_field_name",
141
+ # where="data_source_type_id = %s AND field_id = %s",
142
+ # params=(data_source_type_id, field_id))
148
143
 
149
144
  # if data_source_field_tuples:
150
- #
145
+ #
151
146
  # return data_source_field_tuples[0][0]
152
147
  # return
153
148
 
154
149
  # 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
150
+ # ans: csv_path is the full path to the csv file, directory_name is the directory where the csv file is located
156
151
 
157
152
  # 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
153
+ # ans: it cannot be after directory_name and csv_path because it is a required parameter
159
154
 
160
155
  # TODO: break this function into smaller functions
161
156
  def insert_update_contact_from_csv(
@@ -176,8 +171,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
176
171
 
177
172
  # TODO Please explain
178
173
  # 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
174
+ # if csv_path is not provided then we will use the directory_name and file_name to create the full path
175
+ # 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
176
  if csv_path is not None:
182
177
  csv_file_path = csv_path
183
178
  else:
@@ -198,7 +193,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
198
193
  # We create a new data_source_instance_id everytime we import a new csv file
199
194
  data_source_instance_id = self.__get_data_source_instance_id(
200
195
  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,
196
+ user_external_id=user_external_id, file_name=file_name,
202
197
  user_external_username=user_external_username,
203
198
  start_index=start_index, end_index=end_index
204
199
  )
@@ -211,16 +206,16 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
211
206
  if end_index is not None and not start_index <= row_index <= end_index:
212
207
  continue
213
208
  csv_keys = list(row.keys())
214
- contact_data = {}
209
+ contact_dict = {}
215
210
  '''
216
211
  # Old version
217
212
  for fields in keys:
218
213
  if fields_dictonary[fields] not in csv_keys:
219
214
  continue
220
215
  if fields_dictonary[fields] is not None and isinstance(fields_dictonary[fields], str):
221
- contact_data[fields] = row[fields_dictonary[fields]]
216
+ contact_dict[fields] = row[fields_dictonary[fields]]
222
217
  else:
223
- contact_data[fields] = None
218
+ contact_dict[fields] = None
224
219
  '''
225
220
  splitter = ' ::: '
226
221
  for field in keys:
@@ -233,77 +228,78 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
233
228
  values_list = row[field_value].split(splitter)
234
229
  for index, value in enumerate(values_list):
235
230
  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]
231
+ if not contact_dict.get(current_field):
232
+ contact_dict[current_field] = value
233
+ elif not contact_dict.get(field):
234
+ contact_dict[field] = row[field_value]
240
235
  else:
241
- contact_data[field] = None
236
+ contact_dict[field] = None
242
237
 
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')):
238
+ contact_dict = {key: contact_dict.get(
239
+ key) or None for key in contact_fields_to_keep}
240
+ if (not contact_dict.get('first_name')
241
+ and not contact_dict.get('last_name')
242
+ and not contact_dict.get('organization')):
247
243
  continue
248
- contact_data['is_test_data'] = self.is_test_data
244
+ contact_dict['is_test_data'] = self.is_test_data
249
245
 
250
246
  # TODO Please call get_display_name(first_name, last_name, organization) if display_as is empty
251
247
 
252
248
  # for phone in ['phone1', 'phone2', 'phone3']:
253
- # if contact_data[phone] is None:
249
+ # if contact_dict[phone] is None:
254
250
  # continue
255
- # phone_data = process_phone(original_phone_number=contact_data[phone])
251
+ # phone_data = process_phone(original_phone_number=contact_dict[phone])
256
252
  # if phone_data is None:
257
253
  # continue
258
254
  # else:
259
- # contact_data[phone] = phone_data['normalized_phone_number']
255
+ # contact_dict[phone] = phone_data['normalized_phone_number']
260
256
 
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'])
257
+ # contact_dict['first_name'] = process_first_name(
258
+ # original_first_name=contact_dict['first_name'])
259
+ # contact_dict['last_name'] = process_last_name(
260
+ # original_last_name=contact_dict['last_name'])
265
261
 
266
262
  # TODO This should be executed also by Google Contact Sync (please make sure it is in people-local-python-package
267
263
  # 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']
264
+ if contact_dict.get('display_as') is None:
265
+ contact_dict['display_as'] = contact_dict.get(
266
+ 'first_name') or "" # prevent None
267
+ if (contact_dict.get('last_name')
268
+ and not contact_dict.get('last_name').isdigit()):
269
+ contact_dict['display_as'] += " " + contact_dict['last_name']
270
+ if not contact_dict['display_as'] and contact_dict.get('organization'):
271
+ contact_dict['display_as'] += " " + contact_dict['organization']
275
272
 
276
- # TODO if contact_data['display_as'] still empty raise?
273
+ # TODO if contact_dict['display_as'] still empty raise?
277
274
 
278
- # TODO process_notes( contact_data[notes] )
275
+ # TODO process_notes( contact_dict[notes] )
279
276
 
280
277
  # 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)
278
+ contact_dict["data_source_instance_id"] = data_source_instance_id
279
+ contact_dict["source"] = "Import"
280
+ contact_id = self.contacts_local.upsert_contact_dict(contact_dict=contact_dict)
284
281
  if contact_id:
285
282
  self.__insert_contact_details_to_db(
286
- contact_id=contact_id, contact_dict=contact_data, user_external_id=user_external_id,
283
+ contact_id=contact_id, contact_dict=contact_dict, user_external_id=user_external_id,
287
284
  data_source_instance_id=data_source_instance_id,
288
285
  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'])
286
+ contact_data_by_contact_id_dict[contact_id] = contact_dict
287
+ # groups_linked_by_job_title = process_job_title(contact_id=contact_id, job_title=contact_dict['job_title'])
291
288
  # if groups_linked_by_job_title is None:
292
289
  # logger.info("No groups linked by job title to contact " + str(contact_id))
293
290
 
294
-
295
291
  return contact_data_by_contact_id_dict
296
292
 
297
-
298
293
  # TODO def insert_update_contact_groups_from_contact_notes( contact_notes: str) -> int:
299
294
  # TODO Add contact_group with seq, attribute, is_sure using group-local-python-package
300
295
 
301
296
  # TODO def process_people_url( people_url ) -> str:
302
297
  # TODO Use regex to extract the data from the URL
303
298
  # TODO add to user_external using user-external-python-package
299
+
304
300
  @staticmethod
305
301
  def process_url(original_url: str) -> str:
306
- prefixes = ['http://', 'https://']
302
+ prefixes = ['http://', 'https://'] # noqa
307
303
  for prefix in prefixes:
308
304
  if original_url.startswith(prefix):
309
305
  original_url = original_url[len(prefix):]
@@ -313,7 +309,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
313
309
 
314
310
  return original_url
315
311
 
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
312
+ # 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
313
 
318
314
  def process_notes(self, contact_note: str) -> None:
319
315
  # TODO number_of_system_recommednded_groups_identified_in_contact_notes = get_system_recommended_groups_from_contact_notes( contact_notes: str)
@@ -338,44 +334,38 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
338
334
  :param location_type_name: The location type name
339
335
  :return: The location type ID
340
336
  """
341
- location_type_id = self.select_one_value_by_id(
337
+ location_type_id = self.select_one_value_by_column_and_value(
342
338
  schema_name="location", view_table_name="location_type_ml_view",
343
339
  select_clause_value="location_type_id", column_name="title", column_value=location_type_name)
344
340
  return location_type_id
345
341
 
346
- def __insert_contact_details_to_db(self, contact_id: int, contact_dict: dict, user_external_id: int,
342
+ def __insert_contact_details_to_db(self, *, contact_id: int, contact_dict: dict, user_external_id: int,
347
343
  data_source_instance_id: int, data_source_type_id: int) -> int:
348
-
349
- location_id = DEFAULT_LOCATION_ID
350
344
  # insert organization
351
345
  organization_id = self.__insert_organization(contact_dict=contact_dict)
352
346
 
353
347
  # insert link contact_location
354
348
  # The location is in contact_dict
355
349
  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
350
+ contact_dict=contact_dict, contact_id=contact_id) or [{}]
351
+ location_id = location_results[0].get(
352
+ "location_id") or DEFAULT_LOCATION_ID
353
+ country_id = location_results[0].get("country_id")
360
354
 
361
355
  # insert link contact_group
362
356
  self.__insert_link_contact_groups(
363
357
  contact_dict=contact_dict, contact_id=contact_id)
364
358
 
365
359
  # insert link contact_persons
366
- self.__insert_link_contact_persons(
367
- contact_dict=contact_dict, contact_id=contact_id)
360
+ contact_person_result_dict = self.__insert_link_contact_persons(
361
+ contact_dict=contact_dict, contact_id=contact_id) or {}
362
+ person_id = contact_person_result_dict.get("person_id")
368
363
 
369
364
  # 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
365
+ contact_profile_info = self.__insert_contact_profiles(
366
+ contact_dict=contact_dict, contact_id=contact_id) or {}
367
+
368
+ profile_id = contact_profile_info.get("profile_id") or DEFAULT_PROFILE_ID
379
369
 
380
370
  # insert organization-profile
381
371
  self.__insert_organization_profile(
@@ -386,13 +376,13 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
386
376
  contact_dict=contact_dict, contact_id=contact_id)
387
377
 
388
378
  # 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)
379
+ self.__insert_link_contact_notes_and_text_blocks(
380
+ contact_dict=contact_dict, contact_id=contact_id, profile_id=profile_id)
392
381
 
393
382
  # insert link contact_phones
394
383
  self.__insert_link_contact_phones(
395
- contact_dict=contact_dict, contact_id=contact_id)
384
+ contact_dict=contact_dict, contact_id=contact_id, profile_id=profile_id,
385
+ person_id=person_id, location_id=location_id, country_id=country_id)
396
386
 
397
387
  # inset link contact_user_externals
398
388
  self.__insert_link_contact_user_external(
@@ -410,9 +400,9 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
410
400
  data_source_type_id=data_source_type_id
411
401
  )
412
402
  return importer_id
413
-
403
+
414
404
  def __insert_organization(self, contact_dict: dict) -> int or None:
415
-
405
+
416
406
  if not contact_dict.get("organization"):
417
407
  return
418
408
  organization_dict = self.__create_organization_dict(
@@ -421,11 +411,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
421
411
  organization_dict=organization_dict)
422
412
  organization_id = organization_upsert_result.get("organization_id")
423
413
  organization_ml_ids_list = organization_upsert_result.get("organization_ml_ids_list") # noqa
424
-
414
+
425
415
  return organization_id
426
416
 
427
417
  def __create_organization_dict(self, organization_name: str) -> dict:
428
-
418
+
429
419
  organization_dict = {
430
420
  "is_approved": 0,
431
421
  "is_main": 1,
@@ -452,22 +442,21 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
452
442
  "is_name_approved": 0,
453
443
  "is_description_approved": 0
454
444
  }
455
-
445
+
456
446
  return organization_dict
457
447
 
458
448
  def __insert_organization_profile(self, organization_id: int, profile_id: int) -> int or None:
459
-
449
+
460
450
  if not organization_id or not profile_id:
461
-
462
451
  return
463
452
 
464
453
  organization_profile_id = self.organization_profiles.insert_mapping_if_not_exists(
465
454
  organization_id=organization_id, profile_id=profile_id)
466
-
455
+
467
456
  return organization_profile_id
468
457
 
469
458
  def __insert_link_contact_groups(self, contact_dict: dict, contact_id: int) -> list:
470
-
459
+
471
460
  groups = []
472
461
  groups_linked = None
473
462
  if contact_dict.get("organization"):
@@ -476,23 +465,24 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
476
465
  groups.append(contact_dict.get("job_title"))
477
466
  if len(groups) > 0:
478
467
  groups_linked = self.contact_groups.insert_link_contact_group_with_group_local(
479
- contact_id=contact_id, groups=groups)
480
-
468
+ contact_id=contact_id, groups_names=groups)
469
+
481
470
  return groups_linked
482
471
 
483
- def __insert_link_contact_persons(self, contact_dict: dict, contact_id: int) -> int:
484
-
472
+ def __insert_link_contact_persons(self, contact_dict: dict, contact_id: int) -> dict:
485
473
  contact_person_results_dict = self.contact_persons.insert_contact_and_link_to_existing_or_new_person(
486
474
  contact_dict=contact_dict,
487
475
  contact_email_address=contact_dict["email1"],
488
- contact_id=contact_id
476
+ contact_id=contact_id,
477
+ contact_normalized_phone_number=contact_dict.get("phone1"),
478
+ # TODO: what about phone2 etc?
489
479
  )
490
- contact_person_id = contact_person_results_dict.get("contact_person_id")
491
-
492
- return contact_person_id
480
+ # contact_person_id = contact_person_results_dict.get("contact_person_id")
481
+
482
+ return contact_person_results_dict
493
483
 
494
484
  def __insert_link_contact_email_addresses(self, contact_dict, contact_id) -> list[int]:
495
-
485
+
496
486
  email_addresses = self.contacts_local.get_contact_email_addresses_from_contact_dict(
497
487
  contact_dict=contact_dict)
498
488
  contact_email_addresses = self.contact_email_addresses
@@ -504,7 +494,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
504
494
  contact_id=contact_id
505
495
  )
506
496
  contact_email_address_ids.append(contact_email_address_id)
507
-
497
+
508
498
  return contact_email_address_ids
509
499
 
510
500
  @staticmethod
@@ -513,47 +503,52 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
513
503
  if not contact_dict.get("notes"):
514
504
  return
515
505
  # 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)
506
+ contact_notes = ContactNotesLocal(
507
+ contact_dict=contact_dict, contact_id=contact_id, profile_id=profile_id)
517
508
  insert_information = contact_notes.insert_contact_notes_text_block()
518
509
  contact_note_id = insert_information.get("contact_note_id")
519
510
  return contact_note_id
520
511
 
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)
512
+ def __insert_link_contact_phones(self, contact_dict: dict, contact_id: int, profile_id: int, person_id: int,
513
+ location_id: int, country_id: int) -> list[int]:
514
+
515
+ phone_numbers = self.contacts_local.get_contact_phone_numbers_from_contact_dict(
516
+ contact_dict=contact_dict)
524
517
  contact_phone_ids = []
525
518
  for phone_number in phone_numbers:
526
519
  contact_phone_id = self.contact_phone.insert_contact_and_link_to_existing_or_new_phone(
527
520
  contact_dict=contact_dict,
528
521
  phone_number=phone_number,
529
- contact_id=contact_id
522
+ contact_id=contact_id,
523
+ profile_id=profile_id,
524
+ person_id=person_id,
525
+ location_id=location_id,
526
+ country_id=country_id
530
527
  )
531
- contact_phone_ids.append(contact_phone_id)
532
-
528
+ contact_phone_ids.append(contact_phone_id.get("contact_phone_id"))
529
+
533
530
  return contact_phone_ids
534
531
 
535
532
  def __insert_link_contact_user_external(self, contact_dict: dict, contact_id: int) -> int:
536
-
533
+
537
534
  contact_user_external_id = self.contact_user_external.insert_contact_and_link_to_existing_or_new_user_external(
538
535
  contact_dict=contact_dict,
539
536
  contact_email_address=contact_dict["email1"],
540
537
  contact_id=contact_id,
541
538
  user_external_dict={"username": contact_dict["email1"]}
542
539
  )
543
-
540
+
544
541
  return contact_user_external_id
545
542
 
546
543
  def __insert_contact_profiles(self, contact_dict: dict, contact_id: int) -> dict:
547
-
544
+
548
545
  insert_information = self.contact_profiles.insert_and_link_contact_profile(
549
- contact_dict=contact_dict,
550
- contact_id=contact_id
551
- )
552
-
546
+ contact_dict=contact_dict, contact_id=contact_id)
547
+
553
548
  return insert_information
554
549
 
555
550
  def __insert_link_contact_domains(self, contact_dict: dict, contact_id: int) -> list[dict]:
556
-
551
+
557
552
  website_count = 1
558
553
  website_url = contact_dict.get("website" + str(website_count))
559
554
  domain_insert_information_list = []
@@ -563,11 +558,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
563
558
  domain_insert_information_list.append(domain_insert_information)
564
559
  website_count += 1
565
560
  website_url = contact_dict.get("website" + str(website_count))
566
-
561
+
567
562
  return domain_insert_information_list
568
563
 
569
564
  def __insert_link_contact_location(self, contact_dict: dict, contact_id: int) -> list[dict] or None:
570
-
565
+
571
566
  location_dicts = self.__procces_location_of_contact(contact_dict)
572
567
  if not location_dicts:
573
568
  return
@@ -598,7 +593,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
598
593
  user_external_id=user_external_id,
599
594
  google_people_api_resource_name=google_people_api_resource_name
600
595
  )
601
-
596
+
602
597
  return importer_id
603
598
 
604
599
  def __procces_location_of_contact(self, contact_dict: dict) -> dict or None:
@@ -607,7 +602,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
607
602
  :param contact_dict: location_dict
608
603
  :return: location_dict
609
604
  """
610
-
605
+
611
606
  address_street1 = contact_dict.get("address1_street")
612
607
  address_city1 = contact_dict.get("address1_city")
613
608
  address_state1 = contact_dict.get("address1_state")
@@ -625,9 +620,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
625
620
 
626
621
  phone_numbers_list = self.__get_phone_numbers_list(contact_dict)
627
622
  email_addresses_list = self.__get_email_addresses_list(contact_dict)
628
- if (not is_contact_location1
623
+ if (not is_contact_location1
629
624
  and not is_contact_location2
630
- and not phone_numbers_list
625
+ and not phone_numbers_list
626
+ and not phone_numbers_list
631
627
  and not email_addresses_list):
632
628
  return
633
629
  # TODO: How can we add location type?
@@ -655,11 +651,11 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
655
651
  country = Country.get_country_name_by_phone_number(phone_number)
656
652
  except NumberParseException as number_parse_exception:
657
653
  self.logger.error("Error while parsing phone number",
658
- object={"number_parse_exception": number_parse_exception})
654
+ object={"number_parse_exception": number_parse_exception})
659
655
  continue
660
656
  except Exception as exception:
661
657
  self.logger.error("Error while getting country name by phone number",
662
- object=exception)
658
+ object=exception)
663
659
  continue
664
660
  currect_location_dict = {
665
661
  "address_local_language": None,
@@ -687,7 +683,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
687
683
  "region": LocationLocalConstants.DEFAULT_REGION_NAME,
688
684
  }
689
685
  proccessed_location_dicts.append(currect_location_dict)
690
-
686
+
691
687
  return proccessed_location_dicts
692
688
 
693
689
  @staticmethod
@@ -704,23 +700,25 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
704
700
  "state": address_state or LocationLocalConstants.DEFAULT_STATE_NAME,
705
701
  "region": LocationLocalConstants.DEFAULT_REGION_NAME,
706
702
  }
707
-
703
+
708
704
  return location_dict
709
705
 
710
706
  @staticmethod
711
707
  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}")]
708
+ phones_list = [contact_dict.get(f"phone{i}")
709
+ for i in range(1, 4) if contact_dict.get(f"phone{i}")]
713
710
  return phones_list
714
711
 
715
712
  @staticmethod
716
713
  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}")]
714
+ emails_list = [contact_dict.get(f"email{i}")
715
+ for i in range(1, 4) if contact_dict.get(f"email{i}")]
718
716
  # TODO use enum const for "email1" ....
719
717
  return emails_list
720
718
 
721
719
  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(
720
+
721
+ user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
724
722
  select_clause_value="user_external_id", column_name="username",
725
723
  column_value=user_external_username, order_by="user_external_id DESC")
726
724
  if user_external_id is None:
@@ -730,17 +728,19 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
730
728
  system_id=CONTACT_PERSON_PROFILE_CSV_SYSTEM_ID,
731
729
  access_token=""
732
730
  )
733
- user_external_id = self.user_externals_local.select_one_value_by_id(
731
+ user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
734
732
  select_clause_value="user_external_id", column_name="username",
735
733
  column_value=user_external_username, order_by="user_external_id DESC")
736
734
 
737
735
  return user_external_id
738
736
 
739
- def __get_data_source_instance_id(self, data_source_type_id: int, csv_file_path: str, user_external_id: int, file_name: str,
737
+ def __get_data_source_instance_id(self, data_source_type_id: int, csv_file_path: str, user_external_id: int,
738
+ file_name: str,
740
739
  user_external_username: str, start_index: int, end_index: int) -> int:
741
740
  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(
741
+ user_external_username + " 'Google Contact- Google Contact CSV'"
742
+ # TODO: move to data_source
743
+ data_source_instance_id = super().insert(
744
744
  schema_name="data_source_instance",
745
745
  table_name="data_source_instance_table",
746
746
  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.20
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=hZqF8C-Av_uj-ztIZAaHAN7vmyXb20-Ht2uF5H6ZJ6U,40471
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.20.dist-info/METADATA,sha256=nmVSB0kelHtnhD2JAAkHJKoqwpiguiV3ZbCfSMQPgz4,1450
5
+ contact_person_profile_csv_imp_local-0.0.20.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ contact_person_profile_csv_imp_local-0.0.20.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
+ contact_person_profile_csv_imp_local-0.0.20.dist-info/RECORD,,