-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_difference.py
58 lines (45 loc) · 2.24 KB
/
file_difference.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 webbrowser,lcs
from yattag import Doc,indent
def get_file_content(path):
with open(path) as file_content:
return list(file_content)
def generate_html_code(input1,input2,operations):
doc,tag,text,line = Doc().ttl()
with tag('html'):
with tag('head'):
doc._append('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">')
doc._append('<script src="https://use.fontawesome.com/35ac922f38.js"></script>')
with tag('body',klass = 'container bg-light'):
line('h2','file difference',klass = 'text-center')
with tag('div',klass = 'card'): ########3
line('h4', 'File A content = ' + input1)
doc._append('<br>')
line('h4', 'File B content = ' + input2)
line('h6', 'You Can Convert A To B with these operations', klass='text-center display-4')
with tag('div',klass = 'container'):
for i in operations:
if i[0:3] == 'ADD':
with tag('div',klass = "bg-success"):
line('i','',klass = 'fa fa-plus pull-right')
line('h4',i[3:])
elif i[0:3] == 'REM':
with tag('div',klass = "bg-danger"):
line('i','',klass = 'fa fa-remove pull-right')
line('h4',i[3:])
if i[0:3] == 'LCS':
with tag('div',klass = "bg-info"):
line('i','',klass = 'fa fa-star pull-right')
line('h4',i[3:])
return indent(doc.getvalue())
def saveMarkedUpContentToFile(content):
with open('output.html', 'w') as f:
f.write(content)
if __name__ == "__main__" :
input1 = get_file_content('input1.txt')
input2 = get_file_content('input2.txt')
operations = lcs.lcs(input1[0],input2[0])
input1 = ''.join(input1[0])
input2 = ''.join(input2[0])
print operations
content = generate_html_code(input1,input2,operations)
saveMarkedUpContentToFile(content)