Sanitized coding style
parent
e75ef057c7
commit
920cf205de
|
@ -75,29 +75,14 @@ if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Automatically schedule observations on a SatNOGS station.")
|
description="Automatically schedule observations on a SatNOGS station.")
|
||||||
parser.add_argument("-s", "--station", help="Ground station ID", type=int)
|
parser.add_argument("-s", "--station", help="Ground station ID", type=int)
|
||||||
parser.add_argument(
|
parser.add_argument("-t", "--starttime", help="Start time (YYYY-MM-DD HH:MM:SS) [default: now]",
|
||||||
"-t",
|
|
||||||
"--starttime",
|
|
||||||
help="Start time (YYYY-MM-DD HH:MM:SS) [default: now]",
|
|
||||||
default=datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"))
|
default=datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"))
|
||||||
parser.add_argument(
|
parser.add_argument("-d", "--duration", help="Duration to schedule [hours]", type=int, default=1)
|
||||||
"-d",
|
|
||||||
"--duration",
|
|
||||||
help="Duration to schedule [hours]",
|
|
||||||
type=int,
|
|
||||||
default=1)
|
|
||||||
parser.add_argument("-u", "--username", help="SatNOGS username")
|
parser.add_argument("-u", "--username", help="SatNOGS username")
|
||||||
parser.add_argument("-p", "--password", help="SatNOGS password")
|
parser.add_argument("-p", "--password", help="SatNOGS password")
|
||||||
parser.add_argument(
|
parser.add_argument("-n", "--dryrun", help="Dry run (do not schedule passes)", action="store_true")
|
||||||
"-n",
|
parser.add_argument("-l", "--log-level", default="INFO", dest="log_level",
|
||||||
"--dryrun",
|
type=_log_level_string_to_int, nargs="?",
|
||||||
help="Dry run (do not schedule passes)",
|
|
||||||
action="store_true")
|
|
||||||
parser.add_argument("-l", "--log-level",
|
|
||||||
default="INFO",
|
|
||||||
dest="log_level",
|
|
||||||
type=_log_level_string_to_int,
|
|
||||||
nargs="?",
|
|
||||||
help="Set the logging output level. {0}".format(_LOG_LEVEL_STRINGS))
|
help="Set the logging output level. {0}".format(_LOG_LEVEL_STRINGS))
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -105,8 +90,7 @@ if __name__ == "__main__":
|
||||||
numeric_level = args.log_level
|
numeric_level = args.log_level
|
||||||
if not isinstance(numeric_level, int):
|
if not isinstance(numeric_level, int):
|
||||||
raise ValueError("Invalid log level")
|
raise ValueError("Invalid log level")
|
||||||
logging.basicConfig(level=numeric_level,
|
logging.basicConfig(level=numeric_level, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
ground_station_id = args.station
|
ground_station_id = args.station
|
||||||
|
@ -129,27 +113,15 @@ if __name__ == "__main__":
|
||||||
os.mkdir(cache_dir)
|
os.mkdir(cache_dir)
|
||||||
|
|
||||||
# Get last update
|
# Get last update
|
||||||
tlast = get_last_update(
|
tlast = get_last_update(os.path.join(cache_dir, "last_update_%d.txt" % ground_station_id))
|
||||||
os.path.join(
|
|
||||||
cache_dir,
|
|
||||||
"last_update_%d.txt" %
|
|
||||||
ground_station_id))
|
|
||||||
|
|
||||||
# Update logic
|
# Update logic
|
||||||
update = False
|
update = False
|
||||||
if tlast is None or (tnow - tlast).total_seconds() > settings.CACHE_AGE * 3600:
|
if tlast is None or (tnow - tlast).total_seconds() > settings.CACHE_AGE * 3600:
|
||||||
update = True
|
update = True
|
||||||
if not os.path.isfile(
|
if not os.path.isfile(os.path.join(cache_dir, "transmitters_%d.txt" % ground_station_id)):
|
||||||
os.path.join(
|
|
||||||
cache_dir,
|
|
||||||
"transmitters_%d.txt" %
|
|
||||||
ground_station_id)):
|
|
||||||
update = True
|
update = True
|
||||||
if not os.path.isfile(
|
if not os.path.isfile(os.path.join(cache_dir, "tles_%d.txt" % ground_station_id)):
|
||||||
os.path.join(
|
|
||||||
cache_dir,
|
|
||||||
"tles_%d.txt" %
|
|
||||||
ground_station_id)):
|
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
# Update
|
# Update
|
||||||
|
@ -172,25 +144,19 @@ if __name__ == "__main__":
|
||||||
if transmitter["norad_cat_id"] < settings.MAX_NORAD_CAT_ID]))
|
if transmitter["norad_cat_id"] < settings.MAX_NORAD_CAT_ID]))
|
||||||
|
|
||||||
# Store transmitters
|
# Store transmitters
|
||||||
fp = open(
|
fp = open(os.path.join(cache_dir, "transmitters_%d.txt" % ground_station_id), "w")
|
||||||
os.path.join(
|
|
||||||
cache_dir,
|
|
||||||
"transmitters_%d.txt" %
|
|
||||||
ground_station_id),
|
|
||||||
"w")
|
|
||||||
logging.info("Requesting transmitter success rates.")
|
logging.info("Requesting transmitter success rates.")
|
||||||
transmitters_stats = get_transmitter_stats()
|
transmitters_stats = get_transmitter_stats()
|
||||||
for transmitter in transmitters_stats:
|
for transmitter in transmitters_stats:
|
||||||
if not transmitter['uuid'] in transmitters.keys():
|
if not transmitter['uuid'] in transmitters.keys():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fp.write(
|
fp.write("%05d %s %d %d %d\n" %
|
||||||
"%05d %s %d %d %d\n" %
|
(transmitter["norad_cat_id"],
|
||||||
(transmitter["norad_cat_id"],
|
transmitter["uuid"],
|
||||||
transmitter["uuid"],
|
transmitter["success_rate"],
|
||||||
transmitter["success_rate"],
|
transmitter["good_count"],
|
||||||
transmitter["good_count"],
|
transmitter["data_count"]))
|
||||||
transmitter["data_count"]))
|
|
||||||
|
|
||||||
logging.info("Transmitter success rates received!")
|
logging.info("Transmitter success rates received!")
|
||||||
fp.close()
|
fp.close()
|
||||||
|
@ -199,12 +165,7 @@ if __name__ == "__main__":
|
||||||
tles = fetch_tles(norad_cat_ids)
|
tles = fetch_tles(norad_cat_ids)
|
||||||
|
|
||||||
# Store TLEs
|
# Store TLEs
|
||||||
fp = open(
|
fp = open(os.path.join(cache_dir, "tles_%d.txt" % ground_station_id), "w")
|
||||||
os.path.join(
|
|
||||||
cache_dir,
|
|
||||||
"tles_%d.txt" %
|
|
||||||
ground_station_id),
|
|
||||||
"w")
|
|
||||||
for norad_cat_id, (source, tle) in tles.items():
|
for norad_cat_id, (source, tle) in tles.items():
|
||||||
fp.write("%s\n%s\n%s\n" % (tle[0], tle[1], tle[2]))
|
fp.write("%s\n%s\n%s\n" % (tle[0], tle[1], tle[2]))
|
||||||
fp.close()
|
fp.close()
|
||||||
|
@ -232,13 +193,12 @@ if __name__ == "__main__":
|
||||||
item[0]), item[1], float(item[2]) / 100.0, int(item[3]), int(item[4])
|
item[0]), item[1], float(item[2]) / 100.0, int(item[3]), int(item[4])
|
||||||
for tle in tles:
|
for tle in tles:
|
||||||
if tle.id == norad_cat_id:
|
if tle.id == norad_cat_id:
|
||||||
satellites.append(
|
satellites.append(satellite(
|
||||||
satellite(
|
tle,
|
||||||
tle,
|
uuid,
|
||||||
uuid,
|
success_rate,
|
||||||
success_rate,
|
good_count,
|
||||||
good_count,
|
data_count))
|
||||||
data_count))
|
|
||||||
|
|
||||||
# Find passes
|
# Find passes
|
||||||
passes = find_passes(satellites, observer, tmin, tmax, minimum_altitude)
|
passes = find_passes(satellites, observer, tmin, tmax, minimum_altitude)
|
||||||
|
@ -336,15 +296,13 @@ if __name__ == "__main__":
|
||||||
if not satpass['scheduled']:
|
if not satpass['scheduled']:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Scheduling %05d %s %s %3.0f %4.3f %s %s" %
|
"Scheduling %05d %s %s %3.0f %4.3f %s %s" %
|
||||||
(int(
|
(int(satpass['id']),
|
||||||
satpass['id']),
|
satpass['tr'].strftime("%Y-%m-%dT%H:%M:%S"),
|
||||||
satpass['tr'].strftime("%Y-%m-%dT%H:%M:%S"),
|
satpass['ts'].strftime("%Y-%m-%dT%H:%M:%S"),
|
||||||
satpass['ts'].strftime("%Y-%m-%dT%H:%M:%S"),
|
float(satpass['altt']),
|
||||||
float(
|
satpass['priority'],
|
||||||
satpass['altt']),
|
satpass['uuid'],
|
||||||
satpass['priority'],
|
satpass['name'].rstrip()))
|
||||||
satpass['uuid'],
|
|
||||||
satpass['name'].rstrip()))
|
|
||||||
schedule_observation(session,
|
schedule_observation(session,
|
||||||
int(satpass['id']),
|
int(satpass['id']),
|
||||||
satpass['uuid'],
|
satpass['uuid'],
|
||||||
|
|
Loading…
Reference in New Issue