Убрал лишние иморты и библиотеки из pyproject.toml

This commit is contained in:
Павел Синицин 2024-06-22 18:55:10 +03:00
parent 6d5a19c3b0
commit 7c66c6ccbc
Signed by: spavelit
GPG Key ID: 2FEC8CEAE5A95DD1
3 changed files with 89 additions and 112 deletions

View File

@ -1,10 +1,10 @@
import requests
from bpiek import models
AUTH_URL = "https://bp.iek.ru/oauth/login"
API_URL = "https://bp.iek.ru/api/catalog/v1/"
class BPIekApi:
def __init__(self, username, password) -> None:
self.session = requests.Session()
@ -16,25 +16,15 @@ class BPIekApi:
def _login(self) -> None:
auth = self.session.post(
url=f"{AUTH_URL}",
headers={
"Content-Type": "application/x-www-form-urlencoded"
},
data={
"username": self.username,
"password": self.password
}
headers={"Content-Type": "application/x-www-form-urlencoded"},
data={"username": self.username, "password": self.password},
)
def _instance(self, endpoint, params: dict = {}):
response = self.session.get(
url=API_URL + endpoint,
headers={
"Content-Type": "application/json"
},
params={
"format": "json",
**params
}
headers={"Content-Type": "application/json"},
params={"format": "json", **params},
)
return response.json()
@ -43,9 +33,7 @@ class BPIekApi:
try:
result: models.ParentCategoriesResponse = (
models
.ParentCategoriesResponse
.model_validate(response)
models.ParentCategoriesResponse.model_validate(response)
)
return result.categories
@ -57,25 +45,23 @@ class BPIekApi:
response = self._instance(f"client/products/{article}")
try:
result: models.Product = (
models
.Product
.model_validate(response)
)
result: models.Product = models.Product.model_validate(response)
return result
except Exception as e:
return models.Error(code=400, message=str(e))
def get_categories_and_products_by_slug_parent_category(self, slug) -> models.CategoriesAndProductsBySlugParentCategory | models.Error:
def get_categories_and_products_by_slug_parent_category(
self, slug
) -> models.CategoriesAndProductsBySlugParentCategory | models.Error:
response = self._instance(f"client/category/{slug}/json")
try:
result: models.CategoriesAndProductsBySlugParentCategory = (
models
.CategoriesAndProductsBySlugParentCategory
.model_validate(response)
models.CategoriesAndProductsBySlugParentCategory.model_validate(
response
)
)
return result
@ -88,20 +74,16 @@ class BPIekApi:
sortBy: str = "article",
sortOrder: str = "asc",
pageSize: int = 10,
page: int = 1
page: int = 1,
) -> models.NewProductsResponse | models.Error:
response = self._instance("new-products", {
sortBy: sortBy,
sortOrder: sortOrder,
pageSize: pageSize,
page: page
})
response = self._instance(
"new-products",
{sortBy: sortBy, sortOrder: sortOrder, pageSize: pageSize, page: page},
)
try:
result: models.NewProductsResponse = (
models
.NewProductsResponse
.model_validate(response)
models.NewProductsResponse.model_validate(response)
)
return result
@ -109,14 +91,14 @@ class BPIekApi:
except Exception as e:
return models.Error(code=400, message=str(e))
def get_remains_and_planresidues(self, slug) -> models.RemainsAndPlanresiduesResponse | models.Error:
def get_remains_and_planresidues(
self, slug
) -> models.RemainsAndPlanresiduesResponse | models.Error:
response = self._instance(f"client/category/{slug}/balances-json")
try:
result: models.RemainsAndPlanresiduesResponse = (
models
.RemainsAndPlanresiduesResponse
.model_validate(response)
models.RemainsAndPlanresiduesResponse.model_validate(response)
)
return result

View File

@ -3,13 +3,13 @@ from pydantic import BaseModel, ConfigDict, Field
from pydantic.types import UUID1
class Category(BaseModel):
slug: str # Слаг категории
name: str # Название категории
url: str # Относительный адрес категории
apiUrl: str # Ссылка на скачивание файла с содержимым категории
class ProductShort(BaseModel):
class WarehouseData(BaseModel):
class Incoming(BaseModel):
@ -23,7 +23,6 @@ class ProductShort(BaseModel):
availableAmount: int
incoming: list[Incoming]
article: str # Артикул товара
name: str # Полное наименование товара
multiplicity: int | None # Кратность продажи
@ -33,13 +32,13 @@ class ProductShort(BaseModel):
units: str | None # Единицы измерения
warehouseData: list[WarehouseData]
class Product(ProductShort):
class ImageVariant(BaseModel):
url: str # Ссылка
ext: str # Расширение
width: int # Ширина
class Etim(BaseModel):
class EtimClass(BaseModel):
id: str
@ -56,7 +55,6 @@ class Product(ProductShort):
etim_class: EtimClass = Field(alias="class")
features: list[EtimFeatures]
class Complects(BaseModel):
article: str # Артикул
name: str # Наименование
@ -101,7 +99,6 @@ class Product(ProductShort):
description: str
class Videos(BaseModel):
name: str
description: str
url: str
@ -113,9 +110,6 @@ class Product(ProductShort):
url: str
size: str
shortName: str # Краткое название
description: str | None # Описание
categoryName: str | None # Название категории
@ -135,7 +129,9 @@ class Product(ProductShort):
leftPeriod: list[LeftPeriod] | None # Характеристики срока службы
leftPeriodRaw: LeftPeriodRaw # Гарантийные показатели
logisticParams: list[LogisticParams] # Логистические характеристики
logisticParamsData: LogisticParamsData | None # Подробные логистические характеристики
logisticParamsData: (
LogisticParamsData | None
) # Подробные логистические характеристики
novelty: bool # Новинка или нет
designFeatures: list[DesignFeatures] # Отличительные особенности
videos: list[Videos] # Видео по товару
@ -155,12 +151,10 @@ class Product(ProductShort):
isOutOfProduction: bool
class ParentCategoriesResponse(BaseModel):
categories: list[Category]
class CategoriesAndProductsBySlugParentCategory(BaseModel):
date: str
slug: str
@ -169,6 +163,7 @@ class CategoriesAndProductsBySlugParentCategory(BaseModel):
categories: list[Category]
products: list[Product]
class NewProductsResponse(BaseModel):
class Data(BaseModel):
products: list[Product]
@ -182,6 +177,7 @@ class NewProductsResponse(BaseModel):
data: Data
_meta: Meta
class RemainsAndPlanresiduesResponse(BaseModel):
date: str
products: list[ProductShort]

View File

@ -8,7 +8,6 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.12"
requests = "^2.32.3"
loguru = "^0.7.2"
pydantic = "^2.7.4"