Skip to content

Commit d466c39

Browse files
added version errors
added warnings for limits to requests per version to eliminate sending requests that would lead to errors
1 parent 5da832c commit d466c39

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

request.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import ast
44
import pandas as pd
5+
import time
56

67
def flatten_json(nested_json):
78
"""
@@ -27,13 +28,21 @@ def flatten(x, name=''):
2728

2829
flatten(nested_json)
2930
return out
31+
#Sets Post URL
32+
url = 'https://ipgeo.azurewebsites.net/try'
3033

31-
url = 'http://127.0.0.1:5000/try'
32-
34+
#opening list of IP's
3335
with open('ipList.txt', 'r') as f:
3436
ipList = [line.strip() for line in f]
35-
f.close()
37+
f.close()
38+
#checking if IP List is compatible with version
39+
if len(ipList) > 10:
40+
print("Your IP List is longer than 10 entires, which is more than alloted for your version. Sending it would result in an error from the server.")
41+
print("Please shorten your list so that all your IP's may be processed.")
42+
time.sleep(5)
43+
exit()
3644

45+
#Recursively sending requests to the server
3746
for ip in ipList:
3847
ipsearch = "{\n\t\"ip\":\""+ip+"\"\n}"
3948
authentication = {'Content-Type': "application/json"}
@@ -48,7 +57,7 @@ def flatten(x, name=''):
4857
ipAddress = [""+ip+""]
4958
df = pd.Series(data).to_frame().T
5059
df['ip'] = ipAddress
51-
60+
#processing and removing unnecessary fields from the result
5261
if set(['city_names_en','subdivisions_0_names_en']).issubset(df.columns):
5362
df = df[['ip','city_names_en','subdivisions_0_names_en','country_names_en','continent_names_en','location_latitude','location_longitude',
5463
'autonomous_system_number','autonomous_system_organization','isp','organization','organization_type','isic_code','naics_code','connection_type'

0 commit comments

Comments
 (0)