Добавление данных LyngSat в базу
This commit is contained in:
58
dbapp/lyngsatapp/utils.py
Normal file
58
dbapp/lyngsatapp/utils.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from .parser import LyngSatParser
|
||||
from .models import LyngSat
|
||||
from mainapp.models import Polarization, Standard, Modulation, Satellite
|
||||
|
||||
def fill_lyngsat_data(target_sats: list[str]):
|
||||
parser = LyngSatParser(
|
||||
target_sats=target_sats,
|
||||
)
|
||||
lyngsat_data = parser.get_satellites_data()
|
||||
for sat_name, data in lyngsat_data.items():
|
||||
url = data['url']
|
||||
sources = data['sources']
|
||||
for source in sources:
|
||||
try:
|
||||
freq = float(source['freq'])
|
||||
except Exception as e:
|
||||
freq = -1.0
|
||||
print("Беда с частотой")
|
||||
last_update = source['last_update']
|
||||
fec = source['metadata']['fec']
|
||||
modulation = source['metadata']['modulation']
|
||||
standard = source['metadata']['standard']
|
||||
symbol_velocity = source['metadata']['symbol_rate']
|
||||
polarization = source['pol']
|
||||
channel_info = source['provider_name']
|
||||
|
||||
pol_obj, _ = Polarization.objects.get_or_create(
|
||||
name=polarization
|
||||
)
|
||||
|
||||
mod_obj, _ = Modulation.objects.get_or_create(
|
||||
name=modulation
|
||||
)
|
||||
|
||||
standard_obj, _ = Standard.objects.get_or_create(
|
||||
name=standard
|
||||
)
|
||||
|
||||
sat_obj, _ = Satellite.objects.get(
|
||||
name__contains=sat_name
|
||||
)
|
||||
lyng_obj, _ = LyngSat.objects.get_or_create(
|
||||
id_satellite=sat_obj,
|
||||
frequency=freq,
|
||||
polarization=pol_obj,
|
||||
defaults={
|
||||
"modulation": mod_obj,
|
||||
"standard": standard_obj,
|
||||
"sym_velocity": symbol_velocity,
|
||||
"channel_info": channel_info,
|
||||
"last_update": last_update,
|
||||
"fec": fec,
|
||||
"url": url
|
||||
}
|
||||
)
|
||||
lyng_obj.objects.update_or_create()
|
||||
# TODO: сделать карточку и форму для действий и выбора спутника
|
||||
lyng_obj.save()
|
||||
Reference in New Issue
Block a user