forked from km4ack/pi-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinlink-keyword-search
More file actions
141 lines (127 loc) · 3.47 KB
/
winlink-keyword-search
File metadata and controls
141 lines (127 loc) · 3.47 KB
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
#!/bin/bash
#script to scan nearby stations list for specific keywords
#requires that you download nearby stations list with pat winlink before using this script.
#29DEC2022 KM4ACK
#20JUNE2023 edit
eval `pat env`
keyword="green" #default keyword(s) to search for in each line
INBOX=$HOME/.local/share/pat/mailbox/$PAT_MYCALL/in/*
OUTFILE=$HOME/Desktop/call_sign_list.txt
HEADER(){
clear;echo;echo
}
#allow user to change keyword(s) to search
HEADER
echo "Current keyword(s) to search for is \"$keyword\""
echo "1) Continue"
echo "2) Change Keyword"
echo "3) Exit"
read -p "Choose a number " ans
case $ans in
1)
echo "using keyword $keyword"
;;
2)
read -p "New keyword(s)" keyword
;;
3)
echo "73, QRZ"
sleep 1
echo "Nothing heard. This station is QRT"
exit
;;
*)
echo "invalid choice"
exit
;;
esac
#allow user to choose the list to search
MY_LIST(){
if [ -z "$1" ]; then
echo "Keyword to search is \"$keyword\""
echo "Keyword can be changed at top of script";echo
echo "Which list to search"
echo "1) WL2K_Mobiles - List of 100"
echo "2) WL2K_Nearby - List of 30"
echo "3) Cancel and exit"
read -p "Choose a number? " ans
case $ans in
1)
list=WL2K_MOBILES
;;
2)
list=WL2K_NEARBY
;;
3)
echo "73, QRZ"
sleep 1
echo "Nothing heard. This station is QRT"
exit
;;
*)
echo "invalid choice. try again"
sleep 3
HEADER
MY_LIST
;;
esac
else
list=$1
fi
}
HEADER
MY_LIST
#scan emails in inbox to find the list to work with
for files in $INBOX; do
ck=$(grep $list $files)
if [ -n "$ck" ]; then
file=$files
break
fi
done
if [ -z $file ]; then
echo "list not found. download a current nearby or mobile list"
echo "and try again. 73"
exit 1
fi
#scan the list for the keyword in the comments
to=""
echo "scanning $list for keyword \"$keyword\""
while read -r line; do
ck=$(echo $line | grep -i "$keyword")
if [ -n "$ck" ]; then
new=$(echo $line | awk '{print $1}')
to="$to $new"
fi
done < $file
#display results on screen
if [ -z "$to" ]; then
echo "nothing found for keyword \"$keyword\""
echo "exiting in 5 seconds"
sleep 5
else
echo "These stations have \"$keyword\" in the comment section"; echo
echo $to
#give option to compose a message
read -p "Compose a message to these stations? y/n " ans
if [ "$ans" = 'y' ] || [ "$ans" = 'Y' ]; then
read -p "Subject of email? " SUBJECT
echo "The nano editor will open so you can compose the message."
echo "Once complete, press ctrl+s to save and ctrl+x to exit"
echo "and post the message to the Pat outbox"
read -n 1 -s -r -p "Press any key to continue"
nano /run/user/$UID/email.txt
cat /run/user/$UID/email.txt | pat compose $to -s "$SUBJECT"
rm /run/user/$UID/email.txt
fi
#give option to output calls to text file
read -p "Write call sign list to file? y/n " ans
if [ "$ans" = 'y' ] || [ "$ans" = 'Y' ]; then
echo "`date`" > $OUTFILE
echo "These calls found with \"$keyword\" during the search" >> $OUTFILE
echo "" >> $OUTFILE
echo $to >> $OUTFILE
echo "File can be found on your desktop"
echo $OUTFILE
fi
fi