-
Notifications
You must be signed in to change notification settings - Fork 16
/
diff_test.py
56 lines (38 loc) · 1.31 KB
/
diff_test.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
if __name__ == '__main__':
import logSetup
logSetup.initLogging()
import json
import Misc.diff_match_patch as dmp
import WebRequest as wf
def go():
wg = wf.WebGetRobust()
new_content = wg.getpage("http://royalroadl.com/fictions/")
old_content = wg.getpage("http://royalroadl.com/fictions/")
print("Calculating diff")
differ = dmp.diff_match_patch()
diff = differ.patch_make(new_content, old_content)
textdiff = differ.patch_toText(diff)
# print(textdiff)
print(len(new_content), len(old_content), len(diff), len(textdiff))
print(len(old_content.split("\n")), len(new_content.split("\n")))
differ_2 = dmp.diff_match_patch()
d2 = differ_2.patch_fromText(textdiff)
old_content_reconstituted, results = differ_2.patch_apply(d2, new_content)
print(type(old_content_reconstituted))
print("Succeeded: ", old_content == old_content_reconstituted)
# err = differ_2.patch_make(new_content, old_content_reconstituted)
# print(err)
# print(d2)
# import code
# code.interact(local=locals())
# d = difflib.unified_diff(new_content.splitlines(1), old_content.splitlines(1))
# diff = "".join(list(d))
# print(diff)
# print(len(new_content), type(new_content))
# print(len(old_content), type(old_content))
# print(new_content==p2)
# print(d)
# print(len(diff))
# print(wg)
if __name__ == '__main__':
go()