feature/evaluating #2

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

View File

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

View File

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