-
Notifications
You must be signed in to change notification settings - Fork 1
/
yspots
156 lines (126 loc) · 4.42 KB
/
yspots
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
# need both yad and jq for this command to run
#
if [ ! $(which yad) ]; then
echo "you need yad: do sudo apt install yad"
exit 1
fi
if [ ! $(which jq) ]; then
echo "you need jq: do sudo apt install jq"
exit 1
fi
# -b band, -f full screen, -m mode
vtype=right
band=
mode=
while getopts ':b:m:fh' OPTION; do
case "$OPTION" in
f)
vtype=full
;;
b)
band=$(echo "$OPTARG" | sed 's/m//g' | sed 's/c//g')
;;
m)
mode=$(echo "$OPTARG" | tr 'a-z' 'A-Z')
;;
h|?)
echo "Usage: $(basename $0) [-f] [-b band] [-m mode] [-h|-?]"
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
function rowdo {
argument=${4}
if [ ${5} == "SSB" ]; then
setfreq $argument
fi
}
function do_select {
echo in do_select: arguments are: ${@}
line=${@}
echo "$1ine" | sed 's/FALSE//g2' | grep -q -i "false"
err=$?
if [ $err -ne 0 ]; then
echo "$line" | sed 's/^TRUE //' >> $HOME/potaspot.selections
fi
}
export -f do_select
export -f rowdo
function b2fr {
f="$1"
case $1 in
160) range1=1800; range2=2000 ;;
80) range1=3525; range2=4000 ;;
40) range1=7000; range2=7300 ;;
30) range1=10100; range2=10150 ;;
20) range1=14000; range2=14350 ;;
17) range1=18068; range2=18168 ;;
15) range1=21000; range2=21450 ;;
12) range1=24890; range2=24990 ;;
10) range1=28000; range2=29700 ;;
6) range1=50000; range2=54000 ;;
2) range1=144000; range2=148000 ;;
440) range1=420000; range2=450000 ;;
*) range1=0; range2=0 ;;
esac
}
url='https://api.pota.app/spot/activator'
curl -s $url > temp.json
jq 'sort_by([(.mode), (.frequency|tonumber)])' temp.json > temp1.json
if [ ! -z $mode ]; then
jq "map(select(.mode == \"$mode\"))" temp1.json > temp.json
else
mv temp1.json temp.json
fi
if [ ! -z $band ]; then
b2fr $band
jq "map(select((.frequency >= \"$range1\") and (.frequency <= \"$range2\")))" temp.json > spots.json
else
mv temp.json spots.json
fi
n=$(cat spots.json | jq '. [] | {reference: .reference, activatoper: .activator, freq: .frequency}' | jq '. .reference' | wc -l)
let n=$(($n - 1))
rm -f temp.json temp.out.txt
for s in $(seq 0 $n); do
ref=$(cat spots.json | jq ". [$s] | .reference")
activator=$(cat spots.json | jq ". [$s] | .activator")
freq=$(cat spots.json | jq ". [${s}] | .frequency")
loc=$(cat spots.json | jq ". [${s}] | .locationDesc")
grid=$(cat spots.json | jq ". [${s}] | .grid6")
mode=$(cat spots.json | jq ". [${s}] | .mode")
if [ "${mode}" = '""' ]; then
mode='n/a'
fi
# echo "strlen ${freq} ==> ${#freq}"
if [ ${#freq} = 6 ]; then # even though I see 4 chars, #freq reports 6
freq="0${freq}"
fi
sel='FALSE'
if [ -f "$HOME/potaspot.selections" ]; then
v1=$(echo ${ref} | tr -d '"')
v2=$(echo ${activator} | tr -d '"')
if grep -q -i "${v1}.*${v2}" $HOME/potaspot.selections; then
sel='TRUE'
fi
fi
printf "%-s %-10s %-12s %-12s %-8s %-8s %s 16\n" ${sel} ${ref} ${activator} ${freq} ${mode} ${loc:0:10} ${grid} | tr -d '"' >> temp.out.txt
done
gw=$(xdpyinfo | grep dimensions | awk '{print $2}' | tr 'x' ' ' | awk '{print $1}')
gh=$(xdpyinfo | grep dimensions | awk '{print $2}' | tr 'x' ' ' | awk '{print $2}')
let h=$(($gh - 100))
let w=$(($gw - 100))
echo "in rowdo yspots"
txt=( `cat temp.out.txt` )
#--select-action='bash -c "do_select %s"'
if [ $vtype = "full" ]; then
yad --title "POTA Spots" --list --checklist --dclick-action='bash -c "rowdo %s"' --select-action='bash -c "do_select %s"' --width ${w} --height ${h} --posx -1 --posy +0 --fixed --button="Clear saved Pota Spots":"rm -f $HOME/potaspot.selections" --button="Ok" --buttons-layout=center --escape-ok --column Done --column Park --column Activator --column Frequency --column Mode --column Location --column Grid --column @font@ ${txt[@]} > /dev/null 2>&1
else
yad --title "POTA Spots" --list --checklist --dclick-action='bash -c "rowdo %s"' --select-action='bash -c "do_select %s"' --width 800 --height 1000 --posx -1 --posy +0 --fixed --button="Clear saved Pota Spots":"rm -f $HOME/potaspot.selections" --button="Ok" --buttons-layout=center --escape-ok --column Done --column Park --column Activator --column Frequency --column Mode --column Location --column Grid --column @font@ ${txt[@]} > /dev/null 2>&1
fi
[ -f "$HOME/potaspot.selections" ] && (echo -e "you chose ( in ~/potaspot.selections ):\n"; cat $HOME/potaspot.selections)
rm -f temp.out.txt
rm -f spots.json
unset -f do_select
unset -f rowdo