-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbikemi.sh
101 lines (78 loc) · 2.59 KB
/
bikemi.sh
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#######################################################################
# BIKEMI parser - version 0.72 (enough for my purposes)
# Copyright (C) 2008 Andrea Trentini (www.atrent.it)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, browse http://www.gnu.org/licenses/gpl.txt
#######################################################################
# TODO: comincia a diventare lento... ;)
#set -x
function headers()
{
echo "''STAZIONE : NR.BICI (se =0 non ce ne sono) : NR.STALLI DISPONIBILI (se =0 non si possono restituire bici, e' piena la stazione)''"
}
function mycat()
{
head -1 $1
tail -n +2 $1 | while
read riga
do
echo '*' $riga |sed "s/:/\t:\t/g"
done
}
function pagina()
{
echo '= BikeMI by atrent ='
date
echo '== Vuote (non ci sono bici) =='
echo
mycat vuote.txt
echo
echo '== Piene (non si possono restituire bici) =='
echo
mycat piene.txt
echo
echo '= Stato complessivo ='
echo
mycat ultima.txt
}
############# MAIN ###############
#workaround per crontab
cd $(dirname $0)
DATA=data
FILENAME=$DATA/$(date +%y%m%d%H%M).txt
rm local*php local*php.? mappa*aspx 2>/dev/null
wget -q http://www.bikemi.com/it/mappa-stazioni.aspx
touch mappa.aspx
headers >$FILENAME
# qui si potrebbe usare xml2?
# NO, problemi di encoding... lasciamo stare
grep Artem.Google.MarkersBehavior mappa-stazioni.aspx | cut -f2- -d, |rev|cut -f4- -d, |rev |json_pp |grep info|cut -f2- -d: |cut -c82-|sed "s/<\/span><br\/><ul><li>Biciclette disponibili: /:/g"|sed "s/<\/li><li>Biciclette elettriche disponibili: /:/g"|sed "s/<\/li><li>Stalli disponibili: /:/g"|sed "s/<\/li><\/ul><\/div>\"//g"|tr -d "," >>$FILENAME
rm ultima.txt
#inserire fdupes?
ln -s $FILENAME ultima.txt
# vuote o piene
headers >allarmi.txt
grep ':0' ultima.txt >> allarmi.txt
headers >vuote.txt
grep ':0:' ultima.txt >> vuote.txt
headers >piene.txt
grep ':0$' ultima.txt >> piene.txt
### begin HTML
pagina > ultima.wiki
parsewiki ultima.wiki >ultima.html
### end HTML
#prima di fare le stat elimino i file "vuoti"
find data -size -200c|xargs rm 2>/dev/null
gzip -9 $FILENAME