Skip to content
Snippets Groups Projects
Commit ef24efa2 authored by Daniel Brown's avatar Daniel Brown
Browse files

fixing small things

parent 066d6dbe
No related branches found
No related tags found
No related merge requests found
......@@ -116,9 +116,8 @@ def getFinesseDownloadIPGeoData(input_file, output_file):
output_file: Output filename and path
"""
IPGeo = {}
with open(input_file, "r") as data:
with open(output_file, "w") as w:
for line in data:
split = line.split()
file = split[0].lower()
......@@ -134,18 +133,11 @@ def getFinesseDownloadIPGeoData(input_file, output_file):
lon = response.split('\n')[4].split()
if len(lat) == 2 and len(lon) == 2:
IPGeo[ip][0].append(float(lat[1]))
IPGeo[ip][1].append(float(lon[1]))
w.write("%s %g %g\n" % (ip, float(lat[1]), float(lon[1]) ))
else:
response = json.loads(urllib.urlopen('https://freegeoip.net/json/%s' % ip).read())
if 'latitude' in response:
IPGeo[ip][0].append(float(response['latitude']))
IPGeo[ip][1].append(float(response['longitude']))
print response
with open(output_file, "w") as w:
for ip in IPGeo.keys():
w.write("%s %g %g\n" % (ip, IPGeo[ip][0], IPGeo[ip][1]))
w.write("%s %g %g\n" % (ip, float(response['latitude']), float(response['longitude'])))
print(response)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment