-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
35 lines (28 loc) · 920 Bytes
/
data.py
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
import pickle
global bad_ips, ip_objs, country_dict, postal_code
save_file = 'whois.pkl'
file_to_analyze = 'ips'
# save_file = 'temp.pkl'
# file_to_analyze = 'ips_tmp'
class Data():
def __init__(self):
self.bad_ips = []
self.ip_objs = {}
self.country_dict = {}
self.postal_code = {}
self.states = {}
def save_data(self):
with open(save_file, 'wb') as f:
pickle.dump(list(vars(self).values()), f)
def load_data(self):
try:
with open(save_file, 'rb') as f:
self.bad_ips, self.ip_objs, self.country_dict, self.postal_code, self.states = pickle.load(f)
except (ValueError, FileNotFoundError):
return [], {}, {}, {}
g = Data()
if __name__ == "__main__":
# Inspect the order of variables on save/load
g.load_data()
print(list(vars(g).keys()))
# print(list(vars(g).values()))