Skip to content

Commit 4bf5460

Browse files
authored
Merge pull request #2121 from gethvi/asn-update-database-fix
FIX: Fixes update-database script on the last few days of a month.
2 parents 74c5a64 + d8ff651 commit 4bf5460

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

intelmq/bots/experts/asn_lookup/expert.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,26 @@ def update_database(cls, verbose=False):
115115
if verbose:
116116
print("Searching for the latest database update...")
117117
session = create_request_session()
118-
url = "http://archive.routeviews.org/route-views4/bgpdata/"
119-
response = session.get(url)
118+
base_url = "http://archive.routeviews.org/route-views4/bgpdata/"
119+
response = session.get(base_url)
120120
pattern = re.compile(r"href=\"(\d{4}\.\d{2})/\"")
121121
months = pattern.findall(response.text)
122122
months.sort(reverse=True)
123123

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

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

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

0 commit comments

Comments
 (0)