-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18.py
57 lines (45 loc) · 1.29 KB
/
18.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
57
import difflib
def main():
left, right = first_step()
diff = second_step(left, right)
third_step(diff)
def first_step():
deltas = open("swan/deltas", 'r')
left = ""
right = ""
while True:
line = deltas.readline()
if line:
left += line[:53]
left += "\n"
right += line[56:]
else:
break
return left, right
def second_step(left, right):
diff = difflib.ndiff(left.splitlines(keepends=True), right.splitlines(keepends=True))
result = "".join(diff)
return result
def third_step(diff):
plus = open("swan/plus.png", "wb")
subtraction = open("swan/subtraction.png", "wb")
space = open("swan/space.png", "wb")
lines = diff.split("\n")
for line in lines:
if len(line) > 0:
first_byte = line[0]
if first_byte == "+":
write_file(plus, line)
elif first_byte == "-":
write_file(subtraction, line)
elif first_byte == " ":
write_file(space, line)
def write_file(file, strings):
sub_strings = strings[2:]
ary = sub_strings.split(" ")
for point in ary:
if point.isalnum():
b = bytes.fromhex(point)
file.write(b)
if __name__ == "__main__":
main()