feature/evaluating #2
@@ -6,6 +6,9 @@ PASSWORD = "..."
|
|||||||
URL_REPORT = "..."
|
URL_REPORT = "..."
|
||||||
URL_REALISATION = "..."
|
URL_REALISATION = "..."
|
||||||
URL_CONTRAGENTS = "..."
|
URL_CONTRAGENTS = "..."
|
||||||
|
URL_NOMENCLATURE="..."
|
||||||
|
URL_COMPANIES="..."
|
||||||
|
URL_STORAGES ="..."
|
||||||
|
|
||||||
BUYER = "..." #Физические лица-розница
|
BUYER = "..." #Физические лица-розница
|
||||||
COMPANY="..." #Организация_Key
|
COMPANY="..." #Организация_Key
|
||||||
|
|||||||
45
server/backend/api/companies.py
Normal file
45
server/backend/api/companies.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import requests
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
from base64 import b64encode
|
||||||
|
from server.backend.schemas.pydantic import settings
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
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}",
|
||||||
|
"Accept": "application/xml",
|
||||||
|
})
|
||||||
|
|
||||||
|
def fetch_contragents():
|
||||||
|
response = session.get(settings.URL_COMPANIES, timeout=10)
|
||||||
|
response.raise_for_status()
|
||||||
|
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",
|
||||||
|
}
|
||||||
|
rows = []
|
||||||
|
# Парсинг XML-ответа
|
||||||
|
root = ET.fromstring(xml)
|
||||||
|
# Извлечение конкретных данных
|
||||||
|
for entry in root.findall('atom:entry', NS):
|
||||||
|
properties = entry.find('atom:content',NS).find(
|
||||||
|
'm:properties', NS)
|
||||||
|
rows.append({
|
||||||
|
'Ref_Key': properties.findtext('d:Ref_Key', default=None, namespaces=NS),
|
||||||
|
'Description': properties.findtext('d:Description', default=None, namespaces=NS),
|
||||||
|
})
|
||||||
|
df = pd.DataFrame(rows)
|
||||||
|
return df
|
||||||
|
except ET.ParseError:
|
||||||
|
raise
|
||||||
|
xml_data = fetch_contragents()
|
||||||
|
root = parse_contragents(xml_data)
|
||||||
|
print(root)
|
||||||
@@ -14,7 +14,7 @@ session.headers.update({
|
|||||||
})
|
})
|
||||||
|
|
||||||
def fetch_contragents():
|
def fetch_contragents():
|
||||||
response = session.get(settings.URL_CONTRAGENTS, timeout=10)
|
response = session.get(settings.URL_CONTRACTORS, timeout=10)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.text
|
return response.text
|
||||||
|
|
||||||
47
server/backend/api/nomenclature.py
Normal file
47
server/backend/api/nomenclature.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import requests
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
from base64 import b64encode
|
||||||
|
from server.backend.schemas.pydantic import settings
|
||||||
|
import pandas as pd
|
||||||
|
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}",
|
||||||
|
"Accept": "application/xml",
|
||||||
|
})
|
||||||
|
|
||||||
|
def fetch_contragents():
|
||||||
|
response = session.get(settings.URL_NOMENCLATURE, timeout=10)
|
||||||
|
response.raise_for_status()
|
||||||
|
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",
|
||||||
|
}
|
||||||
|
rows = []
|
||||||
|
# Парсинг XML-ответа
|
||||||
|
root = ET.fromstring(xml)
|
||||||
|
# Извлечение конкретных данных
|
||||||
|
for entry in root.findall('atom:entry', NS):
|
||||||
|
properties = entry.find('atom:content',NS).find(
|
||||||
|
'm:properties', NS)
|
||||||
|
rows.append({
|
||||||
|
'Ref_Key': properties.findtext('d:Ref_Key', default=None, namespaces=NS),
|
||||||
|
'Description': properties.findtext('d:Description', default=None, namespaces=NS),
|
||||||
|
'Parent_Key': properties.findtext('d:Parent_Key', default=None, namespaces=NS)
|
||||||
|
})
|
||||||
|
df = pd.DataFrame(rows)
|
||||||
|
df = df[df['Parent_Key'] == 'e0eb911c-03a0-11ef-95bd-fa163e7429d8']
|
||||||
|
df['Description'] = df['Description'].str.extract(r'^([^\s(]+)')
|
||||||
|
return df
|
||||||
|
except ET.ParseError:
|
||||||
|
raise
|
||||||
|
xml_data = fetch_contragents()
|
||||||
|
root = parse_contragents(xml_data)
|
||||||
|
print(root)
|
||||||
45
server/backend/api/storages.py
Normal file
45
server/backend/api/storages.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import requests
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
from base64 import b64encode
|
||||||
|
from server.backend.schemas.pydantic import settings
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
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}",
|
||||||
|
"Accept": "application/xml",
|
||||||
|
})
|
||||||
|
|
||||||
|
def fetch_contragents():
|
||||||
|
response = session.get(settings.URL_STORAGES, timeout=10)
|
||||||
|
response.raise_for_status()
|
||||||
|
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",
|
||||||
|
}
|
||||||
|
rows = []
|
||||||
|
# Парсинг XML-ответа
|
||||||
|
root = ET.fromstring(xml)
|
||||||
|
# Извлечение конкретных данных
|
||||||
|
for entry in root.findall('atom:entry', NS):
|
||||||
|
properties = entry.find('atom:content',NS).find(
|
||||||
|
'm:properties', NS)
|
||||||
|
rows.append({
|
||||||
|
'Ref_Key': properties.findtext('d:Ref_Key', default=None, namespaces=NS),
|
||||||
|
'Description': properties.findtext('d:Description', default=None, namespaces=NS),
|
||||||
|
})
|
||||||
|
df = pd.DataFrame(rows)
|
||||||
|
return df
|
||||||
|
except ET.ParseError:
|
||||||
|
raise
|
||||||
|
xml_data = fetch_contragents()
|
||||||
|
root = parse_contragents(xml_data)
|
||||||
|
print(root)
|
||||||
@@ -17,7 +17,10 @@ class Settings(BaseSettings):
|
|||||||
PASSWORD: str
|
PASSWORD: str
|
||||||
URL_REPORT:str
|
URL_REPORT:str
|
||||||
URL_REALISATION:str
|
URL_REALISATION:str
|
||||||
URL_CONTRAGENTS:str
|
URL_CONTRACTORS:str
|
||||||
|
URL_NOMENCLATURE:str
|
||||||
|
URL_COMPANIES:str
|
||||||
|
URL_STORAGES:str
|
||||||
BUYER: str
|
BUYER: str
|
||||||
COMPANY: str
|
COMPANY: str
|
||||||
STORE: str
|
STORE: str
|
||||||
|
|||||||
Reference in New Issue
Block a user