Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Fix wrong conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jackshendrikov committed Apr 23, 2021
1 parent 2216064 commit a701ee5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ip_locator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.conf import settings

API_KEY = settings.API_KEY
API_IP_KEY = settings.API_IP_KEY


# function to find user's IP location, by default return user IP
Expand All @@ -16,7 +17,7 @@ def find_ip_address(ip=''):
try:
response1 = urlopen("http://ipwhois.app/json/" + ip)
response2 = urlopen("http://ip-api.com/json/" + ip)
response3 = urlopen("http://api.ipapi.com/" + ip + "?access_key=a650836dbd58c826162460691cb51b69")
response3 = urlopen("http://api.ipapi.com/" + ip + "?" + API_IP_KEY)

# return JSON with details about IP address
return [json.load(response1), json.load(response2), json.load(response3)]
Expand Down Expand Up @@ -53,8 +54,8 @@ def analyze_api(data_apis):
if (data_apis[0]['country'] == data_apis[1]['country'] and data_apis[0]['city'] == data_apis[1]['city']) \
or (data_apis[0]['country'] == data_apis[2]['country_name'] and data_apis[0]['city'] == data_apis[2]['city']):
# check equality of lng, lat from API1 and API3
if int(data_apis[0]['latitude']) == int(data_apis[2]['latitude']) \
and int(data_apis[0]['longitude']) == int(data_apis[2]['longitude']):
if int(float(data_apis[0]['latitude'])) == int(data_apis[2]['latitude']) \
and int(float(data_apis[0]['longitude'])) == int(data_apis[2]['longitude']):
data_apis[0]['latitude'] = data_apis[2]['latitude']
data_apis[0]['longitude'] = data_apis[2]['longitude']
return data_apis[0]
Expand All @@ -66,6 +67,7 @@ def analyze_api(data_apis):
for i in range(len(keys1_replace)):
data[keys1_replace[i]] = data_apis[1][keys2_replace[i]]

data['country_flag'] = data_apis[0]['country_flag']
return data
else:
data = data_apis[1]
Expand Down

0 comments on commit a701ee5

Please sign in to comment.