|
12 | 12 | import shutil |
13 | 13 | import sys |
14 | 14 | import csv |
| 15 | +import lzma |
| 16 | +from io import BytesIO |
15 | 17 |
|
16 | 18 | import urllib |
17 | 19 | import urllib.request as request |
|
64 | 66 | 'https://rpki.gin.ntt.net/api/export.json' |
65 | 67 | ] |
66 | 68 | RPKI_ARCHIVE_URLS = [ |
67 | | - 'https://ftp.ripe.net/ripe/rpki/afrinic.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv', |
68 | | - 'https://ftp.ripe.net/ripe/rpki/apnic.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv', |
69 | | - 'https://ftp.ripe.net/ripe/rpki/arin.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv', |
70 | | - 'https://ftp.ripe.net/ripe/rpki/lacnic.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv', |
71 | | - 'https://ftp.ripe.net/ripe/rpki/ripencc.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv', |
| 69 | + 'https://ftp.ripe.net/rpki/afrinic.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv.xz', |
| 70 | + 'https://ftp.ripe.net/rpki/apnic.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv.xz', |
| 71 | + 'https://ftp.ripe.net/rpki/arin.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv.xz', |
| 72 | + 'https://ftp.ripe.net/rpki/lacnic.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv.xz', |
| 73 | + 'https://ftp.ripe.net/rpki/ripencc.tal/{year:04d}/{month:02d}/{day:02d}/roas.csv.xz', |
| 74 | + |
72 | 75 | ] |
73 | 76 | DEFAULT_DELEGATED_URLS = [ |
74 | 77 | 'https://www.nro.net/wp-content/uploads/delegated-stats/nro-extended-stats' |
@@ -459,17 +462,25 @@ def download_databases(self, overwrite=True): |
459 | 462 |
|
460 | 463 | # all files from RIPE's RPKI archive have the same name |
461 | 464 | # 'roas.csv', change it with the tal name |
462 | | - if fname == 'roas.csv': |
463 | | - fname = guess_ta_name(url)+'.csv' |
| 465 | + if fname == 'roas.csv.xz': |
| 466 | + fname = guess_ta_name(url)+".csv" |
464 | 467 |
|
465 | 468 | if os.path.exists(folder+fname) and not overwrite: |
466 | 469 | continue |
467 | 470 |
|
468 | 471 | sys.stderr.write(f'Downloading: {url}\n') |
| 472 | + |
469 | 473 | try: |
470 | | - with closing(request.urlopen(url)) as r: |
471 | | - with open(folder+fname, 'wb') as f: |
472 | | - shutil.copyfileobj(r, f) |
| 474 | + # to separete csv.xz file to decompress |
| 475 | + if "roas.csv.xz" in url: |
| 476 | + with closing(request.urlopen(url)) as response: |
| 477 | + with lzma.open(BytesIO(response.read())) as r: |
| 478 | + with open(folder+fname, 'wb') as f: |
| 479 | + shutil.copyfileobj(r,f) |
| 480 | + else: |
| 481 | + with closing(request.urlopen(url)) as r: |
| 482 | + with open(folder+fname, 'wb') as f: |
| 483 | + shutil.copyfileobj(r, f) |
473 | 484 | except urllib.error.URLError: |
474 | 485 | sys.stderr.write(f'Error {url} is not available.\n') |
475 | | - |
| 486 | + |
0 commit comments