def _get_list_of_data(self, probe_id): list_of_data = [] with open(self.filename) as results: for this_result in results: parsed_result = PingResult.get(this_result) this_probe_id = parsed_result.probe_id # if a probe_id was specified, we only care about that probe's measurements if probe_id != None and this_probe_id != probe_id: continue packets_sent = parsed_result.packets_sent packets_received = parsed_result.packets_received packets_lost = packets_sent - packets_received try: loss_rate = packets_lost/packets_sent except ZeroDivisionError: loss_rate = None data_row = [] for this_attr in self.list_of_headings_and_attr[0]: data_row.append(self._get_attr(this_attr, parsed_result)) list_of_data.append(data_row) return list_of_data
def print_nicely(self, limit): with open(self.filename) as results: i = 0 for result in results.readlines(): if limit is not None: if i >= limit: return parsed_result = PingResult.get(result) print("PROBE ID: "+str(parsed_result.probe_id)) print("firmware: "+str(parsed_result.firmware)) print("origin: "+parsed_result.origin) print("measurement type: "+self.measurement_type) self._print_ping_nicely(parsed_result) print("\n") i +=1
#Read measurement from a URL #https://github.com/RIPE-NCC/ripe.atlas.sagan #Documentation can be found on https://ripe-atlas-sagan.readthedocs.io/en/latest/ import requests from ripe.atlas.sagan import PingResult source = "https://atlas.ripe.net//api/v2/measurements/20335797/results/?format=json" response = requests.get(source).json() for result in response: parsed_result = PingResult.get(result) print(parsed_result.rtt_min)