-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-download
More file actions
executable file
·47 lines (39 loc) · 881 Bytes
/
problem-download
File metadata and controls
executable file
·47 lines (39 loc) · 881 Bytes
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
#!/bin/bash -x
root=$(cd $(dirname $0) && pwd)
cd $root
a=$(cat snapshot | jq -r '.snapshots[] | .snapshot_hash ' | tail -n 1)
b=$(cat lasthash)
if [ "$a" == "$b" ]; then
echo "Same snapshots"
exit 0
fi
echo "update problems.json"
./api-blob $a > problems.json
ret_code=$?
if [ $ret_code != 0 ]; then
echo "Failed to download problems.json"
exit 1
fi
function download() {
id=$1
h=$(echo $2 | sed -e "s/'//g")
if [ -e "problems/${id}.txt" ]; then
echo "Problem $id is already downloaded."
else
while true; do
./api-blob ${h} > "problems/${id}.txt"
ret_code=$?
if [ $ret_code != 0 ]; then
echo "wait for retry.."
sleep 3
else
sleep 3
break
fi
done
fi
}
cat problems.json | jq -r ".problems[] | [.problem_id, .problem_spec_hash] | @sh" | while read line; do
download $line
done
echo $a > "lasthash"