Skip to content

Commit d8ff651

Browse files
author
gethvi
committed
FIX: Fixes update-database script on the last few days of a month.
1 parent 6c89013 commit d8ff651

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
@@ -107,20 +107,26 @@ def update_database(cls):
107107
try:
108108
print("Searching for the latest database update...")
109109
session = create_request_session()
110-
url = "http://archive.routeviews.org/route-views4/bgpdata/"
111-
response = session.get(url)
110+
base_url = "http://archive.routeviews.org/route-views4/bgpdata/"
111+
response = session.get(base_url)
112112
pattern = re.compile(r"href=\"(\d{4}\.\d{2})/\"")
113113
months = pattern.findall(response.text)
114114
months.sort(reverse=True)
115115

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

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

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

0 commit comments

Comments
 (0)