-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.py
More file actions
31 lines (24 loc) · 857 Bytes
/
6.py
File metadata and controls
31 lines (24 loc) · 857 Bytes
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
def oper_file(file_name):
res = {}
with open(file_name) as f:
for line in f:
tmp = line.split(' ')
ip, url = tmp[0], tmp[6]
res[(ip, url)] = res.get((ip, url), 0) + 1
return sorted(res.items(), key=lambda x: x[1], reverse=True)
def get_html(arr):
tmpl = '<tr><td>No%s</td> <td>%s</td><td>%s</td><td>%s</td></tr>'
html_str = '<h1>IP COUNT TABLE</h1>'
html_str += '<table border="1px">'
html_str += tmpl % (' ', 'IP', 'URL', 'COUNT')
for index, value in enumerate(arr[:10]):
html_str += tmpl % (index, value[0][0], value[0][1], value[1])
html_str += '</table>'
return html_str
def start_operate(file_name):
res = oper_file(file_name)
with open('res.html', 'w') as f:
f.write(get_html(res))
f.close()
print(res)
start_operate('log1.log')