Снова улучшения и добавления
This commit is contained in:
@@ -22,7 +22,7 @@ def search_satellite_on_page(data: dict, satellite_name: str):
|
||||
|
||||
def get_footprint_data(position: str = 62) -> dict:
|
||||
"""Возвращает словарь с данным по footprint для спутников на выбранной долготе"""
|
||||
response = requests.get(f"https://www.satbeams.com/footprints?position={position}")
|
||||
response = requests.get(f"https://www.satbeams.com/footprints?position={position}", verify=False)
|
||||
response.raise_for_status()
|
||||
match = re.search(r'var data = ({.*?});', response.text, re.DOTALL)
|
||||
if match:
|
||||
@@ -40,7 +40,7 @@ def get_footprint_data(position: str = 62) -> dict:
|
||||
|
||||
def get_all_page_data(url:str = 'https://www.satbeams.com/footprints') -> dict:
|
||||
"""Возвращает словарь с данными по всем спутникам на странице"""
|
||||
response = requests.get(url)
|
||||
response = requests.get(url, verify="/etc/ssl/certs/ca-certificates.crt")
|
||||
response.raise_for_status()
|
||||
match = re.search(r'var data = ({.*?});', response.text, re.DOTALL)
|
||||
if match:
|
||||
@@ -78,7 +78,14 @@ def get_band_names(satellite_name: str) -> list[str]:
|
||||
names = get_names_footprints_for_satellite(footprints, sat_id)
|
||||
return names
|
||||
|
||||
def parse_transponders_from_json(filepath: str):
|
||||
def parse_transponders_from_json(filepath: str, user=None):
|
||||
"""
|
||||
Парсит транспондеры из JSON файла.
|
||||
|
||||
Args:
|
||||
filepath: путь к JSON файлу
|
||||
user: пользователь для установки created_by и updated_by (optional)
|
||||
"""
|
||||
with open(filepath, encoding="utf-8") as jf:
|
||||
data = json.load(jf)
|
||||
for sat_name, trans_zone in data["satellites"].items():
|
||||
@@ -87,22 +94,40 @@ def parse_transponders_from_json(filepath: str):
|
||||
f_b, f_e = tran["freq"][0].split("-")
|
||||
f = round((float(f_b) + float(f_e))/2, 3)
|
||||
f_range = round(abs(float(f_e) - float(f_b)), 3)
|
||||
tran_obj = Transponders.objects.create(
|
||||
|
||||
pol_obj = Polarization.objects.get(name=tran["pol"])
|
||||
sat_obj = Satellite.objects.get(name__iexact=sat_name)
|
||||
|
||||
tran_obj, created = Transponders.objects.get_or_create(
|
||||
name=tran["name"],
|
||||
frequency=f,
|
||||
frequency_range=f_range,
|
||||
zone_name=zone,
|
||||
polarization=Polarization.objects.get(name=tran["pol"]),
|
||||
sat_id=Satellite.objects.get(name__iexact=sat_name)
|
||||
polarization=pol_obj,
|
||||
sat_id=sat_obj,
|
||||
defaults={
|
||||
"frequency": f,
|
||||
"frequency_range": f_range,
|
||||
"zone_name": zone,
|
||||
}
|
||||
)
|
||||
tran_obj.save()
|
||||
|
||||
# Устанавливаем пользователя, если передан
|
||||
if user:
|
||||
if created:
|
||||
tran_obj.created_by = user
|
||||
tran_obj.updated_by = user
|
||||
tran_obj.save()
|
||||
|
||||
|
||||
# Third-party imports (additional)
|
||||
from lxml import etree
|
||||
|
||||
def parse_transponders_from_xml(data_in: BytesIO, user=None):
|
||||
"""
|
||||
Парсит транспондеры из XML файла.
|
||||
|
||||
Args:
|
||||
data_in: BytesIO объект с XML данными
|
||||
user: пользователь для установки created_by и updated_by (optional)
|
||||
"""
|
||||
tree = etree.parse(data_in)
|
||||
ns = {
|
||||
'i': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
|
||||
Reference in New Issue
Block a user