api 1.4
This commit is contained in:
@@ -2,6 +2,8 @@ import requests
|
||||
import xml.etree.ElementTree as ET
|
||||
from base64 import b64encode
|
||||
from server.backend.schemas.pydantic import settings
|
||||
import re
|
||||
from functools import lru_cache
|
||||
import pandas as pd
|
||||
auth_str = f"{settings.USERNAME}:{settings.PASSWORD}"
|
||||
b64_auth_str = b64encode(auth_str.encode("utf-8")).decode("utf-8")
|
||||
@@ -32,16 +34,32 @@ def parse_contragents(xml: str):
|
||||
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)
|
||||
'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(]+)')
|
||||
df = df[df['parent_key'] == 'e0eb911c-03a0-11ef-95bd-fa163e7429d8']
|
||||
df['description'] = df['description'].str.extract(r'^([^\s(]+)')
|
||||
return df
|
||||
except ET.ParseError:
|
||||
raise
|
||||
def nomenclature():
|
||||
@lru_cache(maxsize=1)
|
||||
def nomenclature(flag=False):
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
if flag:
|
||||
root.to_excel("./excel_files/nomenclature.xlsx")
|
||||
return root
|
||||
def processing(df):
|
||||
df2=nomenclature()
|
||||
result = df.merge(
|
||||
df2[['description', 'ref_key']], #берутся столбцы из df2
|
||||
left_on='arti', #столбец для сравнения в df
|
||||
right_on='description', #столбец для сравнения в df2
|
||||
how='left' #left join для df
|
||||
).drop(columns='description') #удаление временного стобца
|
||||
not_matched = result.loc[result['ref_key'].isna(), 'arti'].unique()
|
||||
if len(not_matched) > 0:
|
||||
raise ValueError(f'Не найдены значения: {not_matched}')
|
||||
return result
|
||||
Reference in New Issue
Block a user