amochka 0.4.6__tar.gz → 0.4.7__tar.gz

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.
Files changed (27) hide show
  1. {amochka-0.4.6 → amochka-0.4.7}/PKG-INFO +1 -1
  2. {amochka-0.4.6 → amochka-0.4.7}/amochka/__init__.py +1 -1
  3. {amochka-0.4.6 → amochka-0.4.7}/amochka.egg-info/PKG-INFO +1 -1
  4. {amochka-0.4.6 → amochka-0.4.7}/etl/loaders.py +15 -1
  5. {amochka-0.4.6 → amochka-0.4.7}/etl/run_etl.py +4 -2
  6. {amochka-0.4.6 → amochka-0.4.7}/pyproject.toml +1 -1
  7. {amochka-0.4.6 → amochka-0.4.7}/README.md +0 -0
  8. {amochka-0.4.6 → amochka-0.4.7}/amochka/client.py +0 -0
  9. {amochka-0.4.6 → amochka-0.4.7}/amochka/errors.py +0 -0
  10. {amochka-0.4.6 → amochka-0.4.7}/amochka/etl.py +0 -0
  11. {amochka-0.4.6 → amochka-0.4.7}/amochka.egg-info/SOURCES.txt +0 -0
  12. {amochka-0.4.6 → amochka-0.4.7}/amochka.egg-info/dependency_links.txt +0 -0
  13. {amochka-0.4.6 → amochka-0.4.7}/amochka.egg-info/requires.txt +0 -0
  14. {amochka-0.4.6 → amochka-0.4.7}/amochka.egg-info/top_level.txt +0 -0
  15. {amochka-0.4.6 → amochka-0.4.7}/etl/__init__.py +0 -0
  16. {amochka-0.4.6 → amochka-0.4.7}/etl/config.py +0 -0
  17. {amochka-0.4.6 → amochka-0.4.7}/etl/extractors.py +0 -0
  18. {amochka-0.4.6 → amochka-0.4.7}/etl/migrations/001_create_tables.sql +0 -0
  19. {amochka-0.4.6 → amochka-0.4.7}/etl/transformers.py +0 -0
  20. {amochka-0.4.6 → amochka-0.4.7}/setup.cfg +0 -0
  21. {amochka-0.4.6 → amochka-0.4.7}/tests/test_cache.py +0 -0
  22. {amochka-0.4.6 → amochka-0.4.7}/tests/test_client.py +0 -0
  23. {amochka-0.4.6 → amochka-0.4.7}/tests/test_etl.py +0 -0
  24. {amochka-0.4.6 → amochka-0.4.7}/tests/test_http.py +0 -0
  25. {amochka-0.4.6 → amochka-0.4.7}/tests/test_notes_events.py +0 -0
  26. {amochka-0.4.6 → amochka-0.4.7}/tests/test_security.py +0 -0
  27. {amochka-0.4.6 → amochka-0.4.7}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amochka
3
- Version: 0.4.6
3
+ Version: 0.4.7
4
4
  Summary: Python library for working with amoCRM API with ETL capabilities
5
5
  Author-email: Timur <timurdt@gmail.com>
6
6
  License: MIT
@@ -2,7 +2,7 @@
2
2
  amochka: Библиотека для работы с API amoCRM.
3
3
  """
4
4
 
5
- __version__ = "0.4.6"
5
+ __version__ = "0.4.7"
6
6
 
7
7
  from .client import AmoCRMClient, CacheConfig
8
8
  from .errors import (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amochka
3
- Version: 0.4.6
3
+ Version: 0.4.7
4
4
  Summary: Python library for working with amoCRM API with ETL capabilities
5
5
  Author-email: Timur <timurdt@gmail.com>
6
6
  License: MIT
@@ -415,12 +415,26 @@ class PostgresLoader:
415
415
  result = cursor.fetchone()
416
416
  return result[0] if result else None
417
417
 
418
- def load_transformed_contact(self, cursor, transformed: TransformedContact) -> int:
418
+ def load_transformed_contact(
419
+ self,
420
+ cursor,
421
+ transformed: TransformedContact,
422
+ user_id_map: Optional[Dict[int, int]] = None,
423
+ ) -> int:
419
424
  """Загружает полностью трансформированный контакт."""
420
425
  contacts_id = self.upsert_contact(cursor, transformed.contact)
421
426
 
422
427
  # Факты по контакту
423
428
  transformed.contact_facts["contacts_id"] = contacts_id
429
+
430
+ # Преобразуем users_id из amoCRM ID во внутренний ID (если найден).
431
+ # Если пользователя нет в маппинге — оставляем внешний ID как есть.
432
+ if user_id_map:
433
+ amo_user_id = transformed.contact_facts.get("users_id")
434
+ if amo_user_id is not None:
435
+ internal_user_id = user_id_map.get(amo_user_id)
436
+ if internal_user_id is not None:
437
+ transformed.contact_facts["users_id"] = internal_user_id
424
438
  registered_id = self._get_or_create_date_id(cursor, transformed.contact_facts.get("created_date"))
425
439
 
426
440
  cursor.execute(
@@ -134,6 +134,7 @@ def sync_leads_with_contacts(
134
134
  with conn.cursor() as cursor:
135
135
  # Проверяем какие контакты уже есть в БД
136
136
  existing_contacts = loader.build_contact_id_map(cursor, mybi_account_id)
137
+ user_id_map = loader.build_user_id_map(cursor, mybi_account_id)
137
138
  missing_contact_ids = contact_ids - set(existing_contacts.keys())
138
139
 
139
140
  if missing_contact_ids:
@@ -141,7 +142,7 @@ def sync_leads_with_contacts(
141
142
 
142
143
  for contact in extractor.iter_contacts(contact_ids=list(missing_contact_ids)):
143
144
  transformed = contact_transformer.transform(contact)
144
- loader.load_transformed_contact(cursor, transformed)
145
+ loader.load_transformed_contact(cursor, transformed, user_id_map)
145
146
  contacts_loaded += 1
146
147
 
147
148
  if contacts_loaded % batch_size == 0:
@@ -292,6 +293,7 @@ def sync_contacts(
292
293
 
293
294
  with loader.connection() as conn:
294
295
  with conn.cursor() as cursor:
296
+ user_id_map = loader.build_user_id_map(cursor, mybi_account_id)
295
297
  for i, contact in enumerate(contacts_iter):
296
298
  contact_id = contact.get("id")
297
299
 
@@ -301,7 +303,7 @@ def sync_contacts(
301
303
  continue
302
304
 
303
305
  transformed = contact_transformer.transform(contact)
304
- loader.load_transformed_contact(cursor, transformed)
306
+ loader.load_transformed_contact(cursor, transformed, user_id_map)
305
307
  loaded_count += 1
306
308
 
307
309
  # Отслеживаем максимальный updated_at
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "amochka"
7
- version = "0.4.6"
7
+ version = "0.4.7"
8
8
  description = "Python library for working with amoCRM API with ETL capabilities"
9
9
  readme = "README.md"
10
10
  authors = [
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes