amochka 0.4.6__py3-none-any.whl → 0.4.7__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.
- amochka/__init__.py +1 -1
- {amochka-0.4.6.dist-info → amochka-0.4.7.dist-info}/METADATA +1 -1
- {amochka-0.4.6.dist-info → amochka-0.4.7.dist-info}/RECORD +7 -7
- {amochka-0.4.6.dist-info → amochka-0.4.7.dist-info}/WHEEL +1 -1
- etl/loaders.py +15 -1
- etl/run_etl.py +4 -2
- {amochka-0.4.6.dist-info → amochka-0.4.7.dist-info}/top_level.txt +0 -0
amochka/__init__.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
amochka/__init__.py,sha256=
|
|
1
|
+
amochka/__init__.py,sha256=1IrHrHoIJWMJgXlmxVzX93HXxTgDL7agZRR7GeP6AiY,925
|
|
2
2
|
amochka/client.py,sha256=zQUy6DhoQfLDnO9q7CxXd28cjLQmwE15MtTGsGYYVSs,91571
|
|
3
3
|
amochka/errors.py,sha256=Rg4U9srjboQwgU3wwhAed0p3vGcc0ZhuyKHIDhYFnp8,1371
|
|
4
4
|
amochka/etl.py,sha256=tzdGPRGxR49aSAjLksic-FqechvDUTfK8ZUUJGuIU7M,8960
|
|
5
5
|
etl/__init__.py,sha256=bp9fPqbKlOc7xzs27diHEvysy1FgBrwlpX6GnR6GL9U,255
|
|
6
6
|
etl/config.py,sha256=BvaGn5BSGMIfvUNNsnap04iy3BHyMOuRX81G7EiLUfE,9032
|
|
7
7
|
etl/extractors.py,sha256=PqjzlmUa8FLZa1z85mP6Y0-s_TH3REqW58632JzRKUc,13047
|
|
8
|
-
etl/loaders.py,sha256=
|
|
9
|
-
etl/run_etl.py,sha256=
|
|
8
|
+
etl/loaders.py,sha256=AA4XDCbre-Y8SrIji5Sk8olW9WvREM9CMuuknFVe5j0,32589
|
|
9
|
+
etl/run_etl.py,sha256=6ieidJiiXOILI1hzFzCCyVjUHX6wCJ-D6556NUqKOxw,26847
|
|
10
10
|
etl/transformers.py,sha256=OwYJ_9l3oqvy2Y3-umXjAGweOIqlfRI0iSiCFPrcQ8E,17867
|
|
11
11
|
etl/migrations/001_create_tables.sql,sha256=YrSaZjpofC1smjYx0bM4eHQumboruIBY3fwRDlJLLSo,15749
|
|
12
|
-
amochka-0.4.
|
|
13
|
-
amochka-0.4.
|
|
14
|
-
amochka-0.4.
|
|
15
|
-
amochka-0.4.
|
|
12
|
+
amochka-0.4.7.dist-info/METADATA,sha256=W_0rYdYd14YBxn0hp625NmZJtVzPVOY-ERR9hdKsrBQ,7530
|
|
13
|
+
amochka-0.4.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
14
|
+
amochka-0.4.7.dist-info/top_level.txt,sha256=grRX8aLFG-yYKPsAqCD6sUBmdLSQeOMHsc9Dl6S7Lzo,12
|
|
15
|
+
amochka-0.4.7.dist-info/RECORD,,
|
etl/loaders.py
CHANGED
|
@@ -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(
|
|
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(
|
etl/run_etl.py
CHANGED
|
@@ -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
|
|
File without changes
|