Created
August 16, 2019 00:29
-
-
Save sdstrowes/ed93d5a78b26eeed461d8a7a86f81c5c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 arrow | |
import json | |
import requests | |
nextpage = "https://atlas.ripe.net:443/api/v2/measurements/?page_size=500&tags=anchoring&type=traceroute" | |
count = 0 | |
total = 0 | |
# 1564773175 None 22494523 6 ICMP probes 6588 us-xqm-as10886 | |
# 1565015752 None 22504964 4 ICMP mesh 6589 de-dus-as58057 | |
# 1565015759 None 22504967 6 ICMP mesh 6589 de-dus-as58057 | |
print("start_ts,stop_ts,msm_id,af,protocol,anchoring_type,target_anchor,anchor_name") | |
while nextpage is not None: | |
# fetch | |
r = requests.get(nextpage) | |
if r.status_code != 200: | |
break | |
response = r.json() | |
nextpage = response['next'] | |
if total == 0: | |
total = response["count"] | |
for i in response["results"]: | |
count += 1 | |
msm_id = str(i["id"]) | |
af = str(i["af"]) | |
tags = i["tags"] | |
start_ts = str(i["start_time"]) | |
stop_ts = str(i["stop_time"]) | |
proto = i["protocol"] | |
status = i["status"] | |
#print(status) | |
if i["status"]["name"] == "Stopped": | |
stop_ts = str(i["status"]["when"]) | |
# elif i["status"]["name"] == "Ongoing": | |
# print(json.dumps(i, indent=2)) | |
elif i["status"]["name"] != "Ongoing": | |
print("Unknown status!") | |
print(i) | |
#print("status " + json.dumps(status)) | |
if stop_ts == "None": | |
stop_ts = "" | |
else: | |
stop_ts = arrow.get(stop_ts).format("YYYY-MM-DD HH:mm:ss") | |
start_ts = arrow.get(start_ts).format("YYYY-MM-DD HH:mm:ss") | |
print("{},{},{},{},{},{},{},{}".format(start_ts, stop_ts, msm_id, af, proto, tags[3], tags[2], tags[1])) | |
#print(json.dumps(i, indent=2)) | |
#print(nextpage) | |
if total != count: | |
print("ERROR: I parsed {} rows but I expected {} rows!".format(count, total)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment