-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiff.py
More file actions
executable file
·132 lines (121 loc) · 2.69 KB
/
diff.py
File metadata and controls
executable file
·132 lines (121 loc) · 2.69 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
import sys
import hashlib
from orderedset import OrderedSet
from sets import Set
def help():
print "Usage: diff.py [file1] [file2]"
print "Search diff in two bases"
print ""
print ""
print "Example: ./diff.py db1.csv db2.csv"
quit()
def die(msg):
print msg+"\n\n"
quit()
def loadBssid(fh):
fh.seek(0)
os = Set()
cnt=0
for line in fh:
cnt+=1
if (cnt < 2):
continue
#%bssid lat lon
try:
(bssid,lat,lon) = line.split("\t")
os.add(bssid)
except:
pass
return os
def loadFull(fh):
fh.seek(0)
os = Set()
cnt=0
for line in fh:
cnt+=1
if (cnt < 2):
continue
#%bssid lat lon
try:
line = line.strip()
os.add(line)
except:
pass
return os
def loadToHash(fh):
fh.seek(0)
os=dict()
cnt=0
for line in fh:
cnt+=1
if (cnt < 2):
continue
#%bssid lat lon
try:
line = line.strip()
(bssid,lat,lon) = line.split("\t")
os[bssid] = hashlib.md5(line).hexdigest()
except:
pass
return os
def showNewAPs(fh,new_os):
fh.seek(0)
cnt=0
for line in fh:
cnt+=1
if (cnt < 2):
continue
try:
line = line.strip()
(bssid,lat,lon) = line.split("\t")
if (bssid in new_os):
print "NEW:{}".format(line)
except:
pass
def main():
if (len(sys.argv) < 3):
help()
try:
file1 = open(sys.argv[1])
except:
die("cant open "+sys.argv[1])
try:
file2 = open(sys.argv[2])
except:
die("cant open "+sys.argv[2])
new=Set()
deleted=Set()
print "INFO:load "+sys.argv[1]
file1_set = loadBssid(file1)
print "INFO:load "+sys.argv[2]
file2_set = loadBssid(file2)
print "INFO:loading done"
new = file2_set - file1_set
deleted = file1_set - file2_set
showNewAPs(file2,new)
for item in deleted:
print "DEL:{}".format(item)
file1_set.clear()
file2_set.clear()
print "INFO:Search modify"
print "INFO:load to Hash:"+sys.argv[1]
file1_dict = loadToHash(file1)
cnt=0
file2.seek(0)
for line in file2:
cnt+=1
if (cnt < 2):
continue
try:
line = line.strip()
(bssid,lat,lon) = line.split("\t")
hashline = hashlib.md5(line).hexdigest()
if (file1_dict[bssid] == hashline ):
continue
print "UPD:{}".format(line)
except:
pass
print "INFO:Finish"
if __name__ == "__main__" :
main()