created groups.json functional
All checks were successful
Build and Run VSTU Schedule Parser / build_and_run (push) Successful in 18s
All checks were successful
Build and Run VSTU Schedule Parser / build_and_run (push) Successful in 18s
This commit is contained in:
41
utils.py
41
utils.py
@@ -1,6 +1,7 @@
|
||||
# Copyright Stanislav Mironov
|
||||
|
||||
import time
|
||||
import traceback
|
||||
import xlrd
|
||||
from coord import Coord
|
||||
from translations import ExcelSheetReader
|
||||
@@ -10,6 +11,46 @@ import hashlib
|
||||
import requests
|
||||
from urllib.parse import urlsplit, urlunsplit, quote
|
||||
|
||||
def get_preferer_facultet(facultets_data: dict, excel_url: str, skip_for=None, ):
|
||||
if skip_for is None:
|
||||
skip_for = []
|
||||
|
||||
for _key, _value in facultets_data.items():
|
||||
if _key.startswith("_"):
|
||||
continue
|
||||
if _key in skip_for:
|
||||
continue
|
||||
|
||||
short_names = _value.get("short_names", None)
|
||||
if short_names is None:
|
||||
continue
|
||||
|
||||
for name in short_names:
|
||||
if name.lower() in excel_url.lower():
|
||||
return _key
|
||||
|
||||
def get_abbrev_for_facultet(facultets_data: dict, facultet_id: str, fallback_not_found="?", fallback_error="?", fallback_no_short_name="?"):
|
||||
if (facultet_id == 'mag'):
|
||||
return "МАГ"
|
||||
if (facultet_id == 'asp'):
|
||||
return "АСП"
|
||||
|
||||
for _key, _value in facultets_data.items():
|
||||
if _key != facultet_id:
|
||||
continue
|
||||
|
||||
short_names = _value.get("short_names", None)
|
||||
if short_names is None:
|
||||
return fallback_no_short_name
|
||||
|
||||
try:
|
||||
return short_names[0]
|
||||
except Exception as e:
|
||||
traceback.print_exception(e)
|
||||
return fallback_error
|
||||
return fallback_not_found
|
||||
|
||||
|
||||
def download_file_from_url(url, output_filename):
|
||||
"""
|
||||
Скачивает файл по URL со спецсимволами и пробелами, сохраняя его под указанным именем.
|
||||
|
||||
Reference in New Issue
Block a user