-
Notifications
You must be signed in to change notification settings - Fork 1
/
annotate_plot_files
executable file
·39 lines (36 loc) · 1.33 KB
/
annotate_plot_files
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
#!/usr/bin/env python3
'''
Convert name to an IP address
'''
import re
import os
import url_ip_utils
def main():
'''
Annotate all of the plot files in this directory - if possible
'''
database = url_ip_utils.LookupUrlIp()
list_of_files = os.listdir("./")
plot_file = re.compile(r"plot_.+\.js")
link_bundles = re.compile(r"(\d+\.\d+\.\d+.\d+<-->\d+\.\d+\.\d+\.\d+)\"")
for file_candidate in list_of_files:
if plot_file.search(file_candidate):
print(file_candidate)
file_handle = open(file_candidate, "r")
big_line = ""
for line in file_handle:
big_line += line
file_handle.close()
list_of_bundles = link_bundles.findall(big_line)
for bundle in list_of_bundles:
ip1, ip2 = bundle.split("<-->")
annotated_ip1 = database.annotate_ip(ip1)
annotated_ip2 = database.annotate_ip(ip2)
annotated_target = annotated_ip1 + "<-->" + annotated_ip2
big_line = big_line.replace('"' + bundle + '"', '"' + annotated_target + '"', 1)
# overwrite the file with an anotated version
file_handle = open(file_candidate, "w")
file_handle.write(big_line)
file_handle.close()
if __name__ == '__main__':
main()