if url is not None and url.lower().startswith('http'):
# flush data from remote url to temp file and unpack from there
with tempfile.NamedTemporaryFile() as tmp_stream:
try:
r = requests.get(url)
except Exception as e:
syslog.syslog(syslog.LOG_ERR, 'geoip update failed : %s' % e)
return result
if r.status_code == 200:
msg = EmailMessage()
msg["Content-Disposition"] = r.headers.get("Content-Disposition", '')
filename = msg.get_filename()
syslog.syslog(syslog.LOG_NOTICE, 'filename : %s .' % filename)
filename = "ipinfo_lite.csv.gz"
tmp_stream.write(r.content)
tmp_stream.seek(0)
if not filename or filename.lower().endswith('.zip'):
syslog.syslog(syslog.LOG_NOTICE, 'found .zip format, process')
cls.process_zip(tmp_stream, result)
elif filename.endswith('.gz'):
syslog.syslog(syslog.LOG_NOTICE, 'found .gz format, process')
cls.process_gzip(tmp_stream, result)
# dump location hash (detect changes in geoIP source selection)
open(cls._src_hash_file, 'w').write(cls._source_hash())
else:
syslog.syslog(syslog.LOG_ERR,
'geoip update failed : %s [http_code: %s]' % (r.text.replace('\n', ''), r.status_code)
)