add a mode to update country codes of all known IPs

This commit is contained in:
Connor Olding 2021-06-09 11:00:54 +02:00
parent 40ddd264fb
commit f0e6f2d6da
2 changed files with 13 additions and 0 deletions

View file

@ -165,6 +165,11 @@ class RespoDB:
execution.completed = completed
self.flush()
def all_ips(self):
assert self._conn is not None
addresses = self._conn.find(TAddress)
return [addr.str for addr in addresses]
def next_record_id(self):
from storm.expr import Add, Max, Coalesce
expr = Add(Coalesce(Max(TRecord.record_id), 0), 1)

View file

@ -265,6 +265,14 @@ async def main(db, filepaths, checks, opts: Options):
async for ip in reader:
await process(ip, reader.total)
if seen == 0:
# no IPs were provided. refresh all the country codes instead.
all_ips = db.all_ips()
for i, ip in enumerate(all_ips):
if opts.progress:
print(f"#{i + 1}/{len(all_ips)}: {ip}", file=stderr)
await opts.ips.put(ip)
await pooler()
await syncing
await opts.ips.put(None) # end of queue