Add tasks for segment sync and posthog sync

This commit is contained in:
Vasilije 2024-09-30 18:30:39 +02:00
parent cce2e386be
commit 1d4e06fdf3

View file

@ -49,6 +49,7 @@ downloads = None
for entry in data['data']: for entry in data['data']:
if entry['date'] == date_str: if entry['date'] == date_str:
downloads = entry['downloads'] downloads = entry['downloads']
category = entry.get('category')
break break
if downloads is None: if downloads is None:
@ -61,16 +62,19 @@ message_id = f"cognee_downloads_{date_str}"
distinct_id = str(uuid.uuid4()) distinct_id = str(uuid.uuid4())
# Send an event to PostHog # Send an event to PostHog
event_name = 'cognee_lib_downloads_with_mirrors' if category == 'with_mirrors' else 'cognee_lib_downloads_without_mirrors'
if event_name == 'cognee_lib_downloads_without_mirrors':
posthog.capture( posthog.capture(
distinct_id=distinct_id, distinct_id=str(uuid.uuid4()),
event='cognee_downloads', event=event_name,
properties={ properties={
'category': category,
'date': date_str, 'date': date_str,
'downloads': downloads, 'downloads': downloads,
} }
) )
print(f"Data for {date_str} updated in PostHog successfully. Downloads is {downloads}")
print(f"Data for {date_str} updated in PostHog successfully.")
# Update the state file # Update the state file
with open(state_file, 'w') as f: with open(state_file, 'w') as f: