This commit is contained in:
2026-01-06 18:06:34 +03:00
parent b184dbb234
commit 58e6ef2d98
9 changed files with 112 additions and 68 deletions

View File

@@ -4,21 +4,18 @@ from base64 import b64encode
from server.backend.schemas.pydantic import settings
from functools import lru_cache
import pandas as pd
auth_str = f"{settings.USERNAME}:{settings.PASSWORD}"
b64_auth_str = b64encode(auth_str.encode("utf-8")).decode("utf-8")
from server.backend.api.session import get_session
session = requests.Session()
session.headers.update({
"Authorization": f"Basic {b64_auth_str}",
session = get_session({
"Accept": "application/xml",
})
def fetch_contragents():
def fetch_nomenclature():
response = session.get(settings.URL_NOMENCLATURE, timeout=10)
response.raise_for_status()
return response.text
def parse_contragents(xml: str):
def parse_nomenclature(xml: str):
try:
NS = {
"atom": "http://www.w3.org/2005/Atom",
@@ -45,8 +42,8 @@ def parse_contragents(xml: str):
raise
@lru_cache(maxsize=1)
def nomenclature(flag=False):
xml_data = fetch_contragents()
root = parse_contragents(xml_data)
xml_data = fetch_nomenclature()
root = parse_nomenclature(xml_data)
if flag:
root.to_excel("./excel_files/nomenclature.xlsx")
return root