forked from FIRSTMap/scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_events
executable file
·50 lines (50 loc) · 2.3 KB
/
get_events
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
#!/bin/bash -f
#get_events
api="https://www.thebluealliance.com/api/v3/events/"
auth="?X-TBA-Auth-Key=$(cat TBA-auth)"
wget -Odata/events-full "$api$(cat year)$auth"
(echo "// Data extracted from thebluealliance.com at $(TZ=utc date -Iseconds)"
echo "// Built by scraper at https://github.com/FIRSTMap/FIRSTMap-scraper"
echo
gawk -F: ' BEGIN {first=1; sn=1
printf "var events = ["
}
/"event_type"/ {event_type[sn]=gensub("\"*, *$","",1,$2);
gsub("^ *\"*","",event_type[sn]);}
/"short_name"/ {short_name[sn]=gensub("\"*, *$","",1,$2);
gsub("^ *\"*","",short_name[sn]);}
/"name"/ {name[sn]=gensub("\"*, *$","",1,$2);
gsub("^ *\"*","",name[sn]);}
/"key"/ {key[sn]=gensub("\"*, *$","",1,$2);
gsub("^ *\"*","",key[sn]);}
/"lat"/ {lat[sn]=gensub("\"*, *$","",1,$2);
gsub("^ *\"*","",lat[sn]);}
/"lng"/ {lng[sn]=gensub("\"*, *$","",1,$2);
gsub("^ *\"*","",lng[sn]);}
/"parent_event_key"/ {pek=gensub("\"*, *$","",1,$2);
gsub("^ *\"*","",pek);}
/^ }/ {
if (pek == "null") {sn++;} }
END {
for (i=1; i<sn; i++) {
ct=0;
for (j=i+1; j<sn; j++) {
if (lat[i]==lat[j] && lng[i]==lng[j]) {
switch (ct%3) {
case 0: lat[j]+=0.0001*(1+int(ct/3)); lng[j]-=0.0001*(1+int(ct/3)); break;;
case 1: lat[j]-=0.0001*(1+int(ct/3)); lng[j]-=0.0001*(1+int(ct/3)); break;;
case 2: lat[j]+=0.0001*(1+int(ct/3)); lng[j]+=0.0001*(1+int(ct/3)); break;;
}
ct++;
}
}
if (ct>0) {lat[i]-=0.0001; lng[i]+=0.0001;}
}
for (i=1; i<sn; i++) {
printf "%s\n {\"key\": \"%s\", \"lat\": %.4f, \"lng\": %.4f, \"type\": \"%s\", \"name\": \"%s\"}",
first ? "" : ",", key[i], lat[i], lng[i], event_type[i]==0 ? "regional":((event_type[i]==3||event_type[i]==4)?"championship":(event_type[i]+0>98)?"offseason":"district"),
(length(short_name[i])>0) ? short_name[i]: name[i]
first=0;
}
printf "\n]\n"
}' data/events-full ) > events.js