api 1.5
This commit is contained in:
@@ -3,22 +3,19 @@ import xml.etree.ElementTree as ET
|
||||
from base64 import b64encode
|
||||
from server.backend.schemas.pydantic import settings
|
||||
import pandas as pd
|
||||
from server.backend.api.session import get_session
|
||||
|
||||
auth_str = f"{settings.USERNAME}:{settings.PASSWORD}"
|
||||
b64_auth_str = b64encode(auth_str.encode("utf-8")).decode("utf-8")
|
||||
|
||||
session = requests.Session()
|
||||
session.headers.update({
|
||||
"Authorization": f"Basic {b64_auth_str}",
|
||||
session = get_session({
|
||||
"Accept": "application/xml",
|
||||
})
|
||||
|
||||
def fetch_contragents():
|
||||
|
||||
def fetch_stores():
|
||||
response = session.get(settings.URL_STORAGES, timeout=10)
|
||||
response.raise_for_status()
|
||||
return response.text
|
||||
|
||||
def parse_contragents(xml: str):
|
||||
def parse_stores(xml: str):
|
||||
try:
|
||||
NS = {
|
||||
"atom": "http://www.w3.org/2005/Atom",
|
||||
@@ -41,6 +38,6 @@ def parse_contragents(xml: str):
|
||||
except ET.ParseError:
|
||||
raise
|
||||
def storages():
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
xml_data = fetch_stores()
|
||||
root = parse_stores(xml_data)
|
||||
root.to_excel("./excel_files/storages.xlsx")
|
||||
Reference in New Issue
Block a user