-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.py
32 lines (28 loc) · 776 Bytes
/
lib.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
import ujson as json
import csv
def import_csv(filename):
try:
asns = []
with open(filename, 'r') as fp:
reader = csv.reader(fp)
for row in reader:
asns+=row
return set([int(asn) for asn in asns])
except Exception:
print('Import Error with file:', filename)
exit()
def import_json(filename):
try:
with open(filename, 'r') as fp:
data = json.load(fp)
return data
except Exception:
print('Import Error with file:', filename)
exit()
def export_json(data, filename):
try:
with open(filename, 'w') as fp:
json.dump(data, fp)
except Exception:
print('Export Error with file:', filename)
exit()