Skip to content

Instantly share code, notes, and snippets.

@kedare
Created February 20, 2019 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kedare/c8b863dbcdc6dfcb2746c82f576fbc72 to your computer and use it in GitHub Desktop.
Save kedare/c8b863dbcdc6dfcb2746c82f576fbc72 to your computer and use it in GitHub Desktop.
py-ris-streamer.py
import json
import websocket
import pymongo
from pprint import pprint
# Mongo Connect
mongo = pymongo.MongoClient("mongodb://ris:ris@localhost:27017")
db = mongo.ris
collection = db.changes
# WS Connect
ws = websocket.WebSocket()
ws.connect("wss://ris-live.ripe.net/v1/ws/?client=py-ris-streamer")
params = {
"moreSpecific": True,
"host": "rrc21",
"socketOptions": {
"includeRaw": True
}
}
ws.send(json.dumps({
"type": "ris_subscribe",
"data": params
}))
# Process data
for data in ws:
loaded_data = json.loads(data)
collection.insert_one(loaded_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment