This commit is contained in:
2025-12-24 19:54:39 +03:00
parent caa23b40b1
commit 1e5492b7b6
2 changed files with 21 additions and 26 deletions

View File

@@ -3,9 +3,9 @@ from requests.auth import HTTPBasicAuth
import xml.etree.ElementTree as ET
from base64 import b64encode
from server.backend.schemas.pydantic import settings
import pandas as pd
auth_str = f"{setting.USERNAME}:{settings.PASSWORD}"
auth_str = f"{settings.USERNAME}:{settings.PASSWORD}"
b64_auth_str = b64encode(auth_str.encode("utf-8")).decode("utf-8")
session = requests.Session()
@@ -20,37 +20,31 @@ def fetch_contragents():
return response.text
def parse_contragents(xml: str):
try:
NS = {
"atom": "http://www.w3.org/2005/Atom",
"m": "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
"d": "http://schemas.microsoft.com/ado/2007/08/dataservices",
}
try:
rows = []
# Парсинг XML-ответа
root = ET.fromstring(xml)
# Извлечение конкретных данных
for entry in root.findall('atom:entry', NS):
properties = entry.find('atom:content',NS).find(
'm:properties', NS)
ref_key = properties.find('d:Ref_Key', NS).text
description = properties.find('d:Description', NS).text
full_name = properties.find(
'd:НаименованиеПолное', NS).text
inn = properties.find('d:ИНН', NS).text
kpp = properties.find('d:КПП', NS).text
creation_date = properties.find('d:ДатаСоздания', NS).text
print(f"Ref_Key: {ref_key}")
print(f"Description: {description}")
print(f"Full Name: {full_name}")
print(f"ИНН: {inn}")
print(f"КПП: {kpp}")
print(f"Дата Создания: {creation_date}")
print("----")
rows.append({
'Ref_Key': properties.findtext('d:Ref_Key', default=None, namespaces=NS),
'Description': properties.findtext('d:Description', default=None, namespaces=NS),
'FullName': properties.findtext('d:НаименованиеПолное', default=None, namespaces=NS),
'INN': properties.findtext('d:ИНН', default=None, namespaces=NS),
'KPP': properties.findtext('d:КПП', default=None, namespaces=NS),
'DoC': properties.findtext('d:ДатаСоздания', default=None, namespaces=NS),
})
df = pd.DataFrame(rows)
return df
except ET.ParseError:
print("Ошибка при парсинге XML.")
return "Error during the parsing process"
xml_data = fetch_contragents()
root = parse_contragents(xml_data)
print(root)

View File

@@ -17,6 +17,7 @@ class Settings(BaseSettings):
PASSWORD: str
URL_REPORT:str
URL_REALISATION:str
URL_CONTRAGENTS:str
BUYER: str
COMPANY: str
STORE: str