diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/aprsd.py b/aprsd.py index f3558ec..348d4d2 100644 --- a/aprsd.py +++ b/aprsd.py @@ -19,7 +19,8 @@ # License GPLv2 # -from fuzzyclock import fuzzy +# python included libs +import argparse import json import urllib import sys @@ -33,12 +34,18 @@ from email.mime.text import MIMEText import subprocess import datetime import calendar -from imapclient import IMAPClient, SEEN import email import threading import signal import pprint +# external lib imports +from imapclient import IMAPClient, SEEN + +# local imports here +from fuzzyclock import fuzzy +import utils + # localization, please edit: HOST = "noam.aprs2.net" # north america tier2 servers round robin 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} 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} + +# command line args +parser = argparse.ArgumentParser() +parser.add_argument("--user", + metavar="", + 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: tn = telnetlib.Telnet(HOST, 14580) except Exception, e: diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..c51b982 --- /dev/null +++ b/utils.py @@ -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', '')