diff --git a/network/base/management/commands/update_all_tle.py b/network/base/management/commands/update_all_tle.py index b4b5ff0..19dc2f6 100644 --- a/network/base/management/commands/update_all_tle.py +++ b/network/base/management/commands/update_all_tle.py @@ -10,16 +10,19 @@ class Command(BaseCommand): def handle(self, *args, **options): - satellites = Satellite.objects.exclude(manual_tle=True) + satellites = Satellite.objects.exclude(manual_tle=True, norad_follow_id__isnull=True) self.stdout.write("==Fetching TLEs==") for obj in satellites: + norad_id = obj.norad_cat_id + if (obj.manual_tle): + norad_id = obj.norad_follow_id try: - sat = satellite(obj.norad_cat_id) + sat = satellite(norad_id) except IndexError: self.stdout.write(('{0} - {1}: TLE not found [error]') - .format(obj.name, obj.norad_cat_id)) + .format(obj.name, norad_id)) continue # Get latest satellite TLE and check if it changed @@ -31,9 +34,9 @@ class Command(BaseCommand): pass if latest_tle == tle[1]: self.stdout.write(('{0} - {1}: TLE already exists [defer]') - .format(obj.name, obj.norad_cat_id)) + .format(obj.name, norad_id)) continue Tle.objects.create(tle0=tle[0], tle1=tle[1], tle2=tle[2], satellite=obj) self.stdout.write(('{0} - {1}: new TLE found [updated]') - .format(obj.name, obj.norad_cat_id)) + .format(obj.name, norad_id)) diff --git a/network/base/migrations/0050_satellite_norad_follow_id.py b/network/base/migrations/0050_satellite_norad_follow_id.py new file mode 100644 index 0000000..c333054 --- /dev/null +++ b/network/base/migrations/0050_satellite_norad_follow_id.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.11 on 2018-12-04 16:33 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0049_auto_20180915_1503'), + ] + + operations = [ + migrations.AddField( + model_name='satellite', + name='norad_follow_id', + field=models.PositiveIntegerField(blank=True, null=True), + ), + ] diff --git a/network/base/models.py b/network/base/models.py index c32951b..9c6e288 100644 --- a/network/base/models.py +++ b/network/base/models.py @@ -255,6 +255,7 @@ class StationStatusLog(models.Model): class Satellite(models.Model): """Model for SatNOGS satellites.""" norad_cat_id = models.PositiveIntegerField() + norad_follow_id = models.PositiveIntegerField(blank=True, null=True) name = models.CharField(max_length=45) names = models.TextField(blank=True) image = models.CharField(max_length=100, blank=True, null=True) diff --git a/network/base/tasks.py b/network/base/tasks.py index 362ec2f..a9ff9ec 100644 --- a/network/base/tasks.py +++ b/network/base/tasks.py @@ -20,11 +20,14 @@ from network.celery import app @app.task(ignore_result=True) def update_all_tle(): """Task to update all satellite TLEs""" - satellites = Satellite.objects.exclude(manual_tle=True) + satellites = Satellite.objects.exclude(manual_tle=True, norad_follow_id__isnull=True) for obj in satellites: + norad_id = obj.norad_cat_id + if (obj.manual_tle): + norad_id = obj.norad_follow_id try: - sat = satellite(obj.norad_cat_id) + sat = satellite(norad_id) except IndexError: continue