-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabc.py
More file actions
71 lines (57 loc) · 1.54 KB
/
abc.py
File metadata and controls
71 lines (57 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import requests
from faker import Faker
import csv
import random
import pandas as pd
from matplotlib import pyplot as plt
def data_generator(faker,url):
r_val = pd.DataFrame()
for i in range(150):
ip = faker.ipv4()
temp_url = url+ip
r = requests.get(temp_url)
data = r.json()
# print(data['country'])
rcd = createRecord(ip,data)
rtemp = pd.DataFrame(rcd,index=[i])
r_val = r_val.append(rcd,ignore_index=True)
r_val.to_csv('random1.csv',index= False)
def createRecord(ip,data):
fake_record = {
"IP" : ip,
"Country" : data["country"],
"City" : data["city"],
"Region": data["regionName"],
"Zip":data["zip"],
"ISP" :data["isp"]
}
return fake_record
def visualize():
pd.set_option('precision', 0)
data = pd.read_csv(r"random1.csv")
plot_data = data.groupby('Country')['City'].count()
plot_data = plot_data.astype(int)
draw(plot_data.plot.bar())
def visualize_2():
data = pd.read_csv(r"random1.csv")
plotData = data[data.Country=="United States"]
plotData = plotData.groupby("Region")["Zip"].size()
print(plotData)
plt.xlabel("City")
plt.ylabel('No. of Requests')
plt.title('For USA')
plt.show(plotData.plot.bar())
plt.show(plotData.plot.pie())
def draw(x):
plt.xlabel("Country")
plt.ylabel('No. of Requests')
# plt.title('Trend in Number of Registrations per Year')
plt.show(x)
def main():
url = "http://ip-api.com/json/"
fake = Faker()
# data_generator(fake,url)
visualize_2()
visualize()
if __name__ == '__main__':
main()