from orbit import satellite

from django.core.management.base import BaseCommand

from base.utils import update_all_satellites
from base.models import Satellite


class Command(BaseCommand):
    help = 'Create initial fixtures'

    def handle(self, *args, **options):

        satellites = Satellite.objets.all()

        for obj in satellites:
            try:
                sat = satellite(obj.norad_cat_id)
            except:
                self.stdout.write(('Satellite {} with Identifier {} does '
                                  'not exist').format(obj.name, obj.norad_cat_id))
                continue

            obj.name = sat.name()
            tle = sat.tle()
            obj.tle0 = tle[0]
            obj.tle1 = tle[1]
            obj.tle2 = tle[2]
            obj.save()
            self.stdout.write(('Satellite {} with Identifier {} '
                              'found [updated]').format(obj.norad_cat_id, obj.name))
Add management command to update all existing satellite tle data