chg: Store the timestamp of the prefixes update

pull/12/head
Raphaël Vinot 2018-07-23 16:02:51 +02:00
parent 97c9acdb7d
commit 85a6f6e223
1 changed files with 2 additions and 1 deletions

View File

@ -50,7 +50,7 @@ class PrefixDatabase():
def _init_routes(self, address_family, root_url, path) -> bool: def _init_routes(self, address_family, root_url, path) -> bool:
self.logger.debug(f'Loading {path}') self.logger.debug(f'Loading {path}')
date = parse(re.findall('(?:.*)/(?:.*)/routeviews-rv[2,6]-(.*)-(?:.*).pfx2as.gz', path)[0]).date().isoformat() date = parse(re.findall('(?:.*)/(?:.*)/routeviews-rv[2,6]-(.*).pfx2as.gz', path)[0]).isoformat()
r = requests.get(root_url.format(path)) r = requests.get(root_url.format(path))
to_import = defaultdict(lambda: {address_family: set(), 'ipcount': 0}) to_import = defaultdict(lambda: {address_family: set(), 'ipcount': 0})
with gzip.open(BytesIO(r.content), 'r') as f: with gzip.open(BytesIO(r.content), 'r') as f:
@ -66,6 +66,7 @@ class PrefixDatabase():
p_asn_meta = self.asn_meta.pipeline() p_asn_meta = self.asn_meta.pipeline()
p.sadd('asns', *to_import.keys()) p.sadd('asns', *to_import.keys())
p_asn_meta.set(f'{address_family}|last', date) # Not necessarely today p_asn_meta.set(f'{address_family}|last', date) # Not necessarely today
p_asn_meta.rpush(f'{address_family}|dates', date)
p_asn_meta.sadd(f'{date}|asns|{address_family}', *to_import.keys()) p_asn_meta.sadd(f'{date}|asns|{address_family}', *to_import.keys())
for asn, data in to_import.items(): for asn, data in to_import.items():
p.sadd(f'{asn}|{address_family}', *data[address_family]) p.sadd(f'{asn}|{address_family}', *data[address_family])