-
Notifications
You must be signed in to change notification settings - Fork 0
/
PastVu GeoArchive.sh
79 lines (73 loc) · 2.08 KB
/
PastVu GeoArchive.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
DB='Геоинформационная система';
API_table='"PastVu"."JSON_API"';
API_URL='https://pastvu.com/api2?method=photo.giveForPage';
PastVuIndex() {
N=$(DB_SQL "SELECT count(*) FROM $API_table WHERE \"Id\"=$1;");
if [ "$N" == "1" ]
then
echo "⭮ $i";
else
JSON=$(wget "$API_URL¶ms={%22cid%22:$1}" -q -O - -U 'Mozilla/5.0 (X11; Linux x86_64...) Gecko/20100101 Firefox/70.0' 2>/dev/null | jq ".result.photo" | sed 's/"/\"/g' | sed "s/'/''/g" ); #| tr -d '\0'
if [ "$JSON" == "" ]; then
void=0;
s='🗴';
JSON='NULL';
else
s='🗸';
if [ "$JSON" == "null" ]; then
JSON='NULL';
void=1;
s='🗴';
else
void=0;
JSON="replace('$JSON', '\u0000', '' )::jsonb";
fi
fi
r=$(DB_SQL "INSERT INTO $API_table (\"Id\", \"JSON\", \"void\") VALUES ($1, $JSON, $void::bool) RETURNING \"Id\";");
echo "$s 🖧 $r $void $2";
fi
}
DB_SQL() {
echo "$1" | psql -d "$DB" -A -t -q;
}
PastVu404() {
wget "$API_URL¶ms={%22cid%22:$1}" -O - >/dev/null;
res="$?";
if [ "$res" == "8" ]
then
r=$(DB_SQL "INSERT INTO $API_table (\"Id\", \"ok\", \"null\") VALUES ($1, 0::bool, 1::bool) RETURNING \"Id\";");
echo "🗴 $r $res 404 ";
elif [ "$res" == "4" ]
then
echo "🗴 $1 Сеть перегружена";
elif [ "$res" == "0" ]
then
echo "🗴 $res $1 Цикл";
#PastVuIndex "$1" "Цикл";
else
echo "- $res $1";
fi
}
PastVu_diapazon (){
n=30;
for ((i=$1; i < $2; i++))
do
i1=$(($i+$n));
N=$(DB_SQL "SELECT count(*) FROM $API_table WHERE \"Id\">=$i AND \"Id\"<$i1;");
if [ "$N" != "$n" ]
then
PastVuIndex "$i"
else
i=$(($i+$n-1));
echo "- +$n $i1";
fi
done
echo "Диапазон обработан $1 -> $2";
}
n_iter=$3;
for ((i=$1; i < $2; i=i+$n_iter))
do
i1=$(($i+$n_iter));
N=$(DB_SQL "SELECT count(*) FROM $API_table WHERE \"Id\">=$i AND \"Id\"<$i1;");
[ "$N" != "$n_iter" ] && echo "Диапазон не полностью заполнен $i" && (PastVu_diapazon "$i" "$i1" &) || echo "v Диапазон заполнен $i";
done