35 lines
1005 B
Python
35 lines
1005 B
Python
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
from datetime import date
|
|
from heasarc.models import INPUT_DATA_DIR
|
|
import datetime
|
|
from django.utils import timezone
|
|
import astropy
|
|
from astropy.io import ascii
|
|
import pandas as pd
|
|
import pymysql
|
|
from heasarc.models import HeasarcSimpleClass
|
|
|
|
def load_heasarc_table(filename):
|
|
data = astropy.table.Table.read(filename, format='ascii.fast_no_header', delimiter=',')
|
|
|
|
cls = HeasarcSimpleClass.objects.all()
|
|
cls.delete()
|
|
|
|
for item in data:
|
|
obj = HeasarcSimpleClass(class_id=int(item[0]),
|
|
class_name=item[1])
|
|
obj.save()
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Initiates data dase'
|
|
|
|
# def add_arguments(self, parser):
|
|
# parser.add_argument('poll_id', nargs='+', type=int)
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
load_heasarc_table('/export/django/srg/data/heasarc_object_class_cut.csv')
|
|
self.stdout.write(self.style.SUCCESS('Done'))
|