Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decompressed roas.csv.xz and changed the urls #118

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions iyp/crawlers/ripe/roa.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import argparse
import logging
import lzma
import os
import sys
from collections import defaultdict
from datetime import datetime, timedelta
from io import BytesIO

import requests

Expand All @@ -25,7 +27,7 @@ def __init__(self, organization, url, name):
self.date_path = f'{now.year}/{now.month:02d}/{now.day:02d}'

# Check if today's data is available
self.url = f'{URL}/afrinic.tal/{self.date_path}/roas.csv'
self.url = f'{URL}/afrinic.tal/{self.date_path}/roas.csv.xz'
req = requests.head(self.url)
if req.status_code != 200:
now -= timedelta(days=1)
Expand All @@ -37,20 +39,21 @@ def __init__(self, organization, url, name):

def run(self):
"""Fetch data from RIPE and push to IYP."""

for tal in TALS:

self.url = f'{URL}/{tal}/{self.date_path}/roas.csv'
self.url = f'{URL}/{tal}/{self.date_path}/roas.csv.xz'
logging.info(f'Fetching ROA file: {self.url}')
req = requests.get(self.url)
if req.status_code != 200:
raise RequestStatusError('Error while fetching data for ' + self.url)

# Decompress the .xz file and read it as CSV
with lzma.open(BytesIO(req.content)) as xz_file:
csv_content = xz_file.read().decode('utf-8').splitlines()

# Aggregate data per prefix
asns = set()

prefix_info = defaultdict(list)
for line in req.text.splitlines():
for line in csv_content:
url, asn, prefix, max_length, start, end = line.split(',')

# Skip header
Expand Down
Loading