Created
February 20, 2019 09:41
-
-
Save kedare/c8b863dbcdc6dfcb2746c82f576fbc72 to your computer and use it in GitHub Desktop.
py-ris-streamer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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