-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
116 lines (106 loc) · 4.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import requests
from models import StockItem, Order, Sale
from database import Database
def fetch_data(api_url, headers):
response = requests.get(api_url, headers=headers)
response.raise_for_status()
return response.json()
def main():
headers = {
'Authorization': ''
}
stocks_url = "https://statistics-api.wildberries.ru/api/v1/supplier/stocks?dateFrom=2023-06-20T00:00:00"
orders_url = "https://statistics-api.wildberries.ru/api/v1/supplier/orders?dateFrom=2023-06-20T00:00:00"
sales_url = "https://statistics-api.wildberries.ru/api/v1/supplier/sales?dateFrom=2023-06-20T00:00:00"
stocks_data = fetch_data(stocks_url, headers)
orders_data = fetch_data(orders_url, headers)
sales_data = fetch_data(sales_url, headers)
db = Database()
for item in stocks_data:
stock_item = StockItem(
last_change_date=item["lastChangeDate"],
warehouse_name=item["warehouseName"],
supplier_article=item["supplierArticle"],
nm_id=item["nmId"],
barcode=item["barcode"],
quantity=item["quantity"],
in_way_to_client=item["inWayToClient"],
in_way_from_client=item["inWayFromClient"],
quantity_full=item["quantityFull"],
category=item["category"],
subject=item["subject"],
brand=item["brand"],
tech_size=item["techSize"],
price=item["Price"],
discount=item["Discount"],
is_supply=item["isSupply"],
is_realization=item["isRealization"],
sc_code=item["SCCode"]
)
db.insert_stock_item(stock_item)
for item in orders_data:
order = Order(
date=item["date"],
last_change_date=item["lastChangeDate"],
warehouse_name=item["warehouseName"],
country_name=item["countryName"],
oblast_okrug_name=item["oblastOkrugName"],
region_name=item["regionName"],
supplier_article=item["supplierArticle"],
nm_id=item["nmId"],
barcode=item["barcode"],
category=item["category"],
subject=item["subject"],
brand=item["brand"],
tech_size=item["techSize"],
income_id=item["incomeID"],
is_supply=item["isSupply"],
is_realization=item["isRealization"],
total_price=item["totalPrice"],
discount_percent=item["discountPercent"],
spp=item["spp"],
finished_price=item["finishedPrice"],
price_with_disc=item["priceWithDisc"],
is_cancel=item["isCancel"],
cancel_date=item["cancelDate"],
order_type=item["orderType"],
sticker=item["sticker"],
g_number=item["gNumber"],
srid=item["srid"]
)
db.insert_order(order)
for item in sales_data:
sale = Sale(
date=item["date"],
last_change_date=item["lastChangeDate"],
warehouse_name=item["warehouseName"],
country_name=item["countryName"],
oblast_okrug_name=item["oblastOkrugName"],
region_name=item["regionName"],
supplier_article=item["supplierArticle"],
nm_id=item["nmId"],
barcode=item["barcode"],
category=item["category"],
subject=item["subject"],
brand=item["brand"],
tech_size=item["techSize"],
income_id=item["incomeID"],
is_supply=item["isSupply"],
is_realization=item["isRealization"],
total_price=item["totalPrice"],
discount_percent=item["discountPercent"],
spp=item["spp"],
payment_sale_amount=item["paymentSaleAmount"],
for_pay=item["forPay"],
finished_price=item["finishedPrice"],
price_with_disc=item["priceWithDisc"],
sale_id=item["saleID"],
order_type=item["orderType"],
sticker=item["sticker"],
g_number=item["gNumber"],
srid=item["srid"]
)
db.insert_sale(sale)
db.close()
if __name__ == "__main__":
main()