-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.sh
executable file
·60 lines (50 loc) · 1.4 KB
/
score.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
#! /bin/sh
REQUEST_RETRY_TIMES=60
type expect >/dev/null 2>&1
has_expect=$?
if [ $has_expect -ne 0 ]; then
# expect not installed
git pull origin master
else
./gpull.sh
fi
day=$(date +"%Y-%m-%d")
last=$(cat ./score.txt | tail -1 | awk '{ print $1 }')
if [ "$day" \< "$last" -o "$day" = "$last" ]; then
echo "has updated, skip"
exit 0
fi
n=1
data=""
usr=$(cat user.txt)
while [ -z "${data}" -a $n -lt ${REQUEST_RETRY_TIMES} ]; do
now=$(date +"%H-%M-%S")
echo "${now} [$n]: start query data at ${now}"
data=$(curl -s "https://www.cnblogs.com/$usr/ajax/sidecolumn.aspx" | grep 'liScore' -A 6 | sed -n -e 3p -e 7p)
now=$(date +"%H-%M-%S")
echo "${now} [$n]: ${data}"
n=$((n+1))
done
if [ -z "${data}" ]; then
echo "fetch score & rank data failed, fatal error!"
exit 1
fi
score=$(echo $data | sed -n 1p)
rank=$(echo $data | sed -n 2p)
echo "$day $score $rank" >> score.txt
git add score.txt
# force to calculate fit params & predicating values
./plot.sh "update_predicating_data"
# to prevent adding predicate_merge.data intermedia file
# git add predicate_*.data
git add predicate_binomial.data
git add predicate_logarithm.data
git add predicate_reciprocal.data
git commit -m "udpate score"
if [ $has_expect -ne 0 ]; then
# expect not installed
git push origin master
else
./gpush.sh
fi
echo "============================================================"