mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-22 08:04:53 -05:00
commit
a8385c6f97
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.pyc
|
29
aprsd.py
29
aprsd.py
@ -19,7 +19,8 @@
|
|||||||
# License GPLv2
|
# License GPLv2
|
||||||
#
|
#
|
||||||
|
|
||||||
from fuzzyclock import fuzzy
|
# python included libs
|
||||||
|
import argparse
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
import sys
|
import sys
|
||||||
@ -33,12 +34,18 @@ from email.mime.text import MIMEText
|
|||||||
import subprocess
|
import subprocess
|
||||||
import datetime
|
import datetime
|
||||||
import calendar
|
import calendar
|
||||||
from imapclient import IMAPClient, SEEN
|
|
||||||
import email
|
import email
|
||||||
import threading
|
import threading
|
||||||
import signal
|
import signal
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
|
# external lib imports
|
||||||
|
from imapclient import IMAPClient, SEEN
|
||||||
|
|
||||||
|
# local imports here
|
||||||
|
from fuzzyclock import fuzzy
|
||||||
|
import utils
|
||||||
|
|
||||||
# localization, please edit:
|
# localization, please edit:
|
||||||
HOST = "noam.aprs2.net" # north america tier2 servers round robin
|
HOST = "noam.aprs2.net" # north america tier2 servers round robin
|
||||||
USER = "KM6XXX-9" # callsign of this aprs client with SSID
|
USER = "KM6XXX-9" # callsign of this aprs client with SSID
|
||||||
@ -54,6 +61,24 @@ shortcuts = {
|
|||||||
email_sent_dict = {} # message_number:time combos so we don't resend the same email in five mins {int:int}
|
email_sent_dict = {} # message_number:time combos so we don't resend the same email in five mins {int:int}
|
||||||
ack_dict = {} # message_nubmer:ack combos so we stop sending a message after an ack from radio {int:int}
|
ack_dict = {} # message_nubmer:ack combos so we stop sending a message after an ack from radio {int:int}
|
||||||
message_number = 0 # current aprs radio message number, increments for each message we send over rf {int}
|
message_number = 0 # current aprs radio message number, increments for each message we send over rf {int}
|
||||||
|
|
||||||
|
# command line args
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--user",
|
||||||
|
metavar="<user>",
|
||||||
|
default=utils.env("APRS_USER"),
|
||||||
|
help="The callsign of this ARPS client with SSID"
|
||||||
|
" Default=env[APRS_USER]")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
if not args.user:
|
||||||
|
print("Missing the aprs user")
|
||||||
|
parser.print_help()
|
||||||
|
parser.exit()
|
||||||
|
else:
|
||||||
|
USER = args.user
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tn = telnetlib.Telnet(HOST, 14580)
|
tn = telnetlib.Telnet(HOST, 14580)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@ -23,38 +23,38 @@ def fuzzy(hour, minute, degree=1):
|
|||||||
Supports two degrees of fuzziness. Set with degree = 1 or degree = 2
|
Supports two degrees of fuzziness. Set with degree = 1 or degree = 2
|
||||||
When degree = 1, time is in quantum of 5 minutes.
|
When degree = 1, time is in quantum of 5 minutes.
|
||||||
When degree = 2, time is in quantum of 15 minutes.'''
|
When degree = 2, time is in quantum of 15 minutes.'''
|
||||||
|
|
||||||
if degree<=0 or degree>2:
|
if degree<=0 or degree>2:
|
||||||
print 'Please use a degree of 1 or 2. Using fuzziness degree=1'
|
print 'Please use a degree of 1 or 2. Using fuzziness degree=1'
|
||||||
degree = 1
|
degree = 1
|
||||||
|
|
||||||
begin = 'It\'s '
|
begin = 'It\'s '
|
||||||
|
|
||||||
f0 = 'almost '
|
f0 = 'almost '
|
||||||
f1 = 'exactly '
|
f1 = 'exactly '
|
||||||
f2 = 'around '
|
f2 = 'around '
|
||||||
|
|
||||||
b0 = ' past '
|
b0 = ' past '
|
||||||
b1 = ' to '
|
b1 = ' to '
|
||||||
|
|
||||||
hourList = ('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve')
|
hourList = ('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve')
|
||||||
|
|
||||||
s1 = s2 = s3 = s4 = ''
|
s1 = s2 = s3 = s4 = ''
|
||||||
base = 5
|
base = 5
|
||||||
|
|
||||||
if degree == 1:
|
if degree == 1:
|
||||||
base = 5
|
base = 5
|
||||||
val = ('Five', 'Ten', 'Quarter', 'Twenty', 'Twenty-Five', 'Half')
|
val = ('Five', 'Ten', 'Quarter', 'Twenty', 'Twenty-Five', 'Half')
|
||||||
elif degree == 2:
|
elif degree == 2:
|
||||||
base = 15
|
base = 15
|
||||||
val = ('Quarter', 'Half')
|
val = ('Quarter', 'Half')
|
||||||
|
|
||||||
dmin = minute % base # to find whether we have to use 'almost', 'exactly' or 'around'
|
dmin = minute % base # to find whether we have to use 'almost', 'exactly' or 'around'
|
||||||
if minute > 30:
|
if minute > 30:
|
||||||
pos = int((60 - minute) / base) #position in the tuple 'val'
|
pos = int((60 - minute) / base) #position in the tuple 'val'
|
||||||
else:
|
else:
|
||||||
pos = int(minute / base)
|
pos = int(minute / base)
|
||||||
|
|
||||||
if dmin == 0:
|
if dmin == 0:
|
||||||
s1 = f1
|
s1 = f1
|
||||||
pos = pos - 1
|
pos = pos - 1
|
||||||
@ -66,9 +66,9 @@ def fuzzy(hour, minute, degree=1):
|
|||||||
s1 = f0
|
s1 = f0
|
||||||
if minute > 30:
|
if minute > 30:
|
||||||
pos = pos -1
|
pos = pos -1
|
||||||
|
|
||||||
s2 = val[pos]
|
s2 = val[pos]
|
||||||
|
|
||||||
if minute <= base/2: # Case like "It's around/exactly Ten"
|
if minute <= base/2: # Case like "It's around/exactly Ten"
|
||||||
s2 = s3 = ''
|
s2 = s3 = ''
|
||||||
s4 = hourList[hour - 12 - 1]
|
s4 = hourList[hour - 12 - 1]
|
||||||
@ -82,7 +82,7 @@ def fuzzy(hour, minute, degree=1):
|
|||||||
else:
|
else:
|
||||||
s3 = b0 # past
|
s3 = b0 # past
|
||||||
s4 = hourList[hour - 12 - 1]
|
s4 = hourList[hour - 12 - 1]
|
||||||
|
|
||||||
return begin + s1 + s2 + s3 + s4
|
return begin + s1 + s2 + s3 + s4
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -90,13 +90,13 @@ def main():
|
|||||||
stm = time.localtime()
|
stm = time.localtime()
|
||||||
h = stm.tm_hour
|
h = stm.tm_hour
|
||||||
m = stm.tm_min
|
m = stm.tm_min
|
||||||
|
|
||||||
if len(sys.argv)>=2:
|
if len(sys.argv)>=2:
|
||||||
try:
|
try:
|
||||||
deg = int(sys.argv[1])
|
deg = int(sys.argv[1])
|
||||||
except:
|
except:
|
||||||
print 'Please use a degree of 1 or 2. Using fuzziness degree=1'
|
print 'Please use a degree of 1 or 2. Using fuzziness degree=1'
|
||||||
|
|
||||||
if len(sys.argv)>=3:
|
if len(sys.argv)>=3:
|
||||||
tm = sys.argv[2].split(':')
|
tm = sys.argv[2].split(':')
|
||||||
try:
|
try:
|
||||||
|
16
utils.py
Normal file
16
utils.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
"""Utilities and helper functions."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import pprint
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def env(*vars, **kwargs):
|
||||||
|
"""This returns the first environment variable set.
|
||||||
|
if none are non-empty, defaults to '' or keyword arg default
|
||||||
|
"""
|
||||||
|
for v in vars:
|
||||||
|
value = os.environ.get(v, None)
|
||||||
|
if value:
|
||||||
|
return value
|
||||||
|
return kwargs.get('default', '')
|
Loading…
Reference in New Issue
Block a user