-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairbreizh_data
executable file
·67 lines (49 loc) · 1.35 KB
/
airbreizh_data
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
58
59
60
61
62
63
64
65
66
#!/bin/bash
set -eo pipefail
[[ "$TRACE" ]] && set -x
# cat /tmp/19 | sed -e '/─/d' -e 's/│/,/g' -e 's/ \{2,\}//g' -e 's/^,//'
# sed -e '/─/d' -e '/│[0-9]/!d' -e 's/│/,/g' -e 's/ \{2,\}//g' -e 's/^,//' /tmp/19
retreive_data() {
local url="$1" ; shift
local tempfile=$(tempfile)
w3m -dump "$url" > $tempfile
echo $tempfile
}
date_to_epoc() {
local day="$1" ; shift
local hour="$1" ; shift
local date=()
date=( ${day//\// } )
date -d"${date[2]}${date[1]}${date[0]} $hour" +%s
}
data_processing() {
local tempfile="$1"
local results=()
local day=""
local hour=""
local date=0
while read line ; do
results=( $line )
day="${results[0]}"
results=( ${results[@]:1} )
hour="${results[0]}"
results=( ${results[@]:1} )
date=$(date_to_epoc "$day" "$hour" )
printf "%s" $date
printf ",%s" ${results[@]}
printf "\n"
done < <(sed -e '/─/d' -e '/│[0-9]/!d' -e 's/│//g' -e 's/ \{2,\}/ /g' -e 's/^,//' $tempfile)
}
main() {
local url="$1" ; shift
local data_file="$1"
local tempfile=""
tempfile=$(retreive_data "$url")
data_processing $tempfile | sort | uniq > ${tempfile}_
mv ${tempfile}_ $tempfile
# ajoute uniquement les nouvelles lignes (celles qui ne sont pas communes à
# data_file et à tempfile
comm -13 $data_file ${tempfile} | sort | uniq >> $data_file
rm $tempfile
}
[[ "$0" == "$BASH_SOURCE" ]] && main "$@"