aprs_sendstatus.py
· 1.4 KiB · Python
Brut
#!/usr/bin/env python3
""" sending aprs status packets for my weather station
Author: Dominic Reich (OE7DRT) <quick.hat4396@qtztsjosmprqmgtunjyf.com>
"""
import aprslib
intervals = (
('weeks', 604800), # 60 * 60 * 24 * 7
('days', 86400), # 60 * 60 * 24
('hours', 3600), # 60 * 60
('minutes', 60),
('seconds', 1),
)
def get_uptime(granularity=2):
with open('/proc/uptime', 'r') as u:
uptime_seconds = int(float(u.readline().split()[0]))
return(display_time(uptime_seconds, granularity))
def display_time(seconds, granularity=2):
result = []
for name, count in intervals:
value = seconds // count
if value:
seconds -= value * count
if value == 1:
name = name.rstrip('s')
result.append("{} {}".format(value, name))
return ', '.join(result[:granularity])
def test():
"""test function"""
print('Uptime: ' + get_uptime())
def main():
"""main func"""
AIS = aprslib.IS("OE7DRT-13", passwd="*****", port=14580)
#AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Running for " + get_uptime(2) + " on https://wx.oe7drt.com\r\n")
try:
AIS.connect()
except TimeoutError:
print("Could not send packets - Timeout.")
except:
print("An unexpected Error occured:")
AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Weatherpage: https://wx.oe7drt.com\r\n")
if __name__ == "__main__":
main()
| 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | """ sending aprs status packets for my weather station |
| 4 | |
| 5 | Author: Dominic Reich (OE7DRT) <quick.hat4396@qtztsjosmprqmgtunjyf.com> |
| 6 | """ |
| 7 | |
| 8 | import aprslib |
| 9 | |
| 10 | |
| 11 | intervals = ( |
| 12 | ('weeks', 604800), # 60 * 60 * 24 * 7 |
| 13 | ('days', 86400), # 60 * 60 * 24 |
| 14 | ('hours', 3600), # 60 * 60 |
| 15 | ('minutes', 60), |
| 16 | ('seconds', 1), |
| 17 | ) |
| 18 | |
| 19 | |
| 20 | def get_uptime(granularity=2): |
| 21 | with open('/proc/uptime', 'r') as u: |
| 22 | uptime_seconds = int(float(u.readline().split()[0])) |
| 23 | |
| 24 | return(display_time(uptime_seconds, granularity)) |
| 25 | |
| 26 | |
| 27 | def display_time(seconds, granularity=2): |
| 28 | result = [] |
| 29 | |
| 30 | for name, count in intervals: |
| 31 | value = seconds // count |
| 32 | if value: |
| 33 | seconds -= value * count |
| 34 | if value == 1: |
| 35 | name = name.rstrip('s') |
| 36 | result.append("{} {}".format(value, name)) |
| 37 | return ', '.join(result[:granularity]) |
| 38 | |
| 39 | |
| 40 | def test(): |
| 41 | """test function""" |
| 42 | print('Uptime: ' + get_uptime()) |
| 43 | |
| 44 | |
| 45 | def main(): |
| 46 | """main func""" |
| 47 | AIS = aprslib.IS("OE7DRT-13", passwd="*****", port=14580) |
| 48 | |
| 49 | #AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Running for " + get_uptime(2) + " on https://wx.oe7drt.com\r\n") |
| 50 | try: |
| 51 | AIS.connect() |
| 52 | except TimeoutError: |
| 53 | print("Could not send packets - Timeout.") |
| 54 | except: |
| 55 | print("An unexpected Error occured:") |
| 56 | |
| 57 | AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Weatherpage: https://wx.oe7drt.com\r\n") |
| 58 | |
| 59 | if __name__ == "__main__": |
| 60 | main() |
| 61 |