Skip to content

Commit

Permalink
Merge pull request #2121 from gethvi/asn-update-database-fix
Browse files Browse the repository at this point in the history
FIX: Fixes update-database script on the last few days of a month.
  • Loading branch information
sebix committed Dec 1, 2021
2 parents 74c5a64 + d8ff651 commit 4bf5460
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions intelmq/bots/experts/asn_lookup/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,26 @@ def update_database(cls, verbose=False):
if verbose:
print("Searching for the latest database update...")
session = create_request_session()
url = "http://archive.routeviews.org/route-views4/bgpdata/"
response = session.get(url)
base_url = "http://archive.routeviews.org/route-views4/bgpdata/"
response = session.get(base_url)
pattern = re.compile(r"href=\"(\d{4}\.\d{2})/\"")
months = pattern.findall(response.text)
months.sort(reverse=True)

if not months:
sys.exit("Database update failed. Couldn't find the latest database update.")

url += str(months[0]) + "/RIBS/"
response = session.get(url)
pattern = re.compile(r"href=\"(rib\.\d{8}\.\d{4}\.bz2)\"")
days = pattern.findall(response.text)
days.sort(reverse=True)
# routeviews website creates next month's directory on 28th of the current month
# therefore on 28th, 29th, 30th, 31st it's necessary to find the second highest month directory
for i in range(2):
url = base_url + str(months[i]) + "/RIBS/"
response = session.get(url)
pattern = re.compile(r"href=\"(rib\.\d{8}\.\d{4}\.bz2)\"")
days = pattern.findall(response.text)
days.sort(reverse=True)
print(url)
if days:
break

if not days:
sys.exit("Database update failed. Couldn't find the latest database update.")
Expand Down

0 comments on commit 4bf5460

Please sign in to comment.