-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript3.bash
executable file
·39 lines (30 loc) · 951 Bytes
/
script3.bash
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 bash
#
# Author: Darwin Shameran <[email protected]>
#
# Description: DV1466 project A: web spider
# Implement a web spider that follows the structure of supplied
# website and generate a GraphViz digraph.
#
set -euo pipefail
main() {
declare -r fn="result"
worklist=$(cat "${fn}")
if [[ ! -e "${fn}.dot" ]]; then
touch "${fn}.dot"
fi
printf "digraph result {\n" > "${fn}.dot"
while read -r line; do
read -a line_array <<< "${line}"
src_domain=${line_array[0]}
src_path=${line_array[1]}
target_domain=${line_array[2]}
target_path=${line_array[3]}
$(printf "\"%s%s\" -> \"%s%s\"\n" "${src_domain}" "${src_path}" \
"${target_domain}" "${target_path}" >> "${fn}.dot")
done <<< "${worklist}"
printf "}" >> "${fn}.dot"
$(dot -Tsvg "${fn}.dot" -o "${fn}.svg") # generate .svg file
}
main "$@"
# vim: set ts=2 sw=2 tw=79 ft=sh foldmethod=marker et :