Browse Source

Add autowx script with docopt, move update-keps to python script command

pull/1/head
squeaky otter 4 years ago
parent
commit
5c94f24c8c
Signed by: dashie GPG Key ID: C2D57B325840B755
  1. 31
      autowx.py
  2. 27
      keps.py
  3. 20
      update-keps.sh

31
autowx.py

@ -0,0 +1,31 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""AutoWX
Usage:
autowx.py update-keps [--config=<cfg>] [--force]
autowx.py auto [--config=<cfg>] [--force-keps-update]
autowx.py web [--config=<cfg>]
autowx.py (-h | --help)
autowx.py --version
Options:
-h --help Show this screen.
--version Show version.
--debug Log debug.
--config=<cfg> Configuration file to use [default: autowx.ini]
"""
from docopt import docopt
import cfg
import keps
if __name__ == '__main__':
arguments = docopt(__doc__, version='AutoWX 1.0')
print(arguments)
config = cfg.get(arguments['--config'])
if arguments['update-keps']:
keps.update_keps(config, arguments['--force'])

27
keps.py

@ -0,0 +1,27 @@
import os
import requests
keps_to_manage = {
'noaa.txt': 'https://www.celestrak.com/NORAD/elements/noaa.txt',
'amateur.txt': 'https://www.celestrak.com/NORAD/elements/amateur.txt',
'cubesat.txt': 'https://www.celestrak.com/NORAD/elements/cubesat.txt',
'weather.txt': 'https://www.celestrak.com/NORAD/elements/weather.txt',
'multi.txt': 'http://www.pe0sat.vgnet.nl/kepler/mykepler.txt',
}
def update_keps(config, force):
for keps_name,keps_url in keps_to_manage.iteritems():
print "Downloading keps {} from {}".format(keps_name, keps_url)
file_destination = os.path.join(config.get('DIRS', 'tle'), keps_name)
if os.path.isfile(file_destination):
if force:
os.unlink(file_destination)
else:
print 'Force not asked, ignoring update.'
continue
r = requests.get(keps_url)
with open(file_destination, "wb") as keps_file:
keps_file.write(r.content)
print "File saved as {}".format(file_destination)

20
update-keps.sh

@ -1,20 +0,0 @@
#!/bin/bash
TLEDIR=/tmp
rm $TLEDIR/noaa.txt
wget -qr https://www.celestrak.com/NORAD/elements/noaa.txt -O $TLEDIR/noaa.txt
rm $TLEDIR/amateur.txt
wget -qr https://www.celestrak.com/NORAD/elements/amateur.txt -O $TLEDIR/amateur.txt
rm $TLEDIR/cubesat.txt
wget -qr https://www.celestrak.com/NORAD/elements/cubesat.txt -O $TLEDIR/cubesat.txt
rm $TLEDIR/weather.txt
wget -qr https://www.celestrak.com/NORAD/elements/weather.txt -O $TLEDIR/weather.txt
rm $TLEDIR/multi.txt
wget -qr http://www.pe0sat.vgnet.nl/kepler/mykepler.txt -O $TLEDIR/multi.txt
echo `date`
echo Updated
Loading…
Cancel
Save