Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SSE Client for Wikimedia
#!/usr/bin/env python3
import json, time, sys, os
from sseclient import SSEClient as EventSource
from import pubsub_v1
project_id = os.environ['PROJECT']
topic_name = os.environ['TOPIC']
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(project_id, topic_name)
futures = dict()
url = ''
keys = ['id', 'timestamp', 'user', 'title']
for event in EventSource(url):
if event.event == 'message':
change = json.loads(
changePub = {k: change.get(k, 0) for k in keys}
except ValueError:
payloadJson = json.dumps(changePub).encode('utf-8')
future = publisher.publish(
topic_path, data=payloadJson)
futures[payloadJson] = future
while futures:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.