feature/evaluating #2

Merged
MH.Dmitrii merged 28 commits from feature/evaluating into main 2026-01-09 10:17:48 +00:00
3 changed files with 58 additions and 0 deletions
Showing only changes of commit caa23b40b1 - Show all commits

View File

@@ -5,6 +5,7 @@ USERNAME = "..."
PASSWORD = "..." PASSWORD = "..."
URL_REPORT = "..." URL_REPORT = "..."
URL_REALISATION = "..." URL_REALISATION = "..."
URL_CONTRAGENTS = "..."
BUYER = "..." #Физические лица-розница BUYER = "..." #Физические лица-розница
COMPANY="..." #Организация_Key COMPANY="..." #Организация_Key

View File

@@ -2,4 +2,5 @@ pandas==2.3.3
openpyxl==3.1.5 openpyxl==3.1.5
pydantic==2.12.3 pydantic==2.12.3
pydantic_settings == 2.12.0 pydantic_settings == 2.12.0
requests==2.32.5
dotenv==0.9.9 dotenv==0.9.9

View File

@@ -0,0 +1,56 @@
import requests
from requests.auth import HTTPBasicAuth
import xml.etree.ElementTree as ET
from base64 import b64encode
from server.backend.schemas.pydantic import settings
auth_str = f"{setting.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}",
"Accept": "application/xml",
})
def fetch_contragents():
response = session.get(settings.URL_CONTRAGENTS, timeout=10)
response.raise_for_status()
return response.text
def parse_contragents(xml: str):
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:
# Парсинг 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("----")
except ET.ParseError:
print("Ошибка при парсинге XML.")
xml_data = fetch_contragents()
root = parse_contragents(xml_data)
print(root)