-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5f92a6
commit e898885
Showing
6 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .wb_shop import WbShop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import datetime | ||
import requests | ||
import json | ||
|
||
class WbShop: | ||
""" | ||
That class represents your shop that you have on Wildberries | ||
""" | ||
def __init__(self, api_key, name = 'Shop') -> None: | ||
self.api = api_key | ||
self.name = name | ||
|
||
def __str__(self): | ||
return f"{self.name}" | ||
|
||
def rsr(self, date_from = datetime.date(1997,8,10), date_to = datetime.date(1997,8,10), data_type = 'json'): | ||
""" | ||
Returns realization sales report | ||
Default timespan is from the last monday to the last sunday | ||
dateFrom and dateTo has to be a datetime.datetime objects | ||
""" | ||
if date_from == datetime.date(1997,8,10) and date_to == datetime.date(1997,8,10): | ||
days_until_sunday = (datetime.date.today().weekday() - 6) % 7 | ||
last_sunday = datetime.date.today() - datetime.timedelta(days = days_until_sunday) | ||
monday = last_sunday - datetime.timedelta(days = 6) | ||
date_from = monday | ||
date_to = last_sunday | ||
|
||
# Authorization parameters | ||
headers = { | ||
'Authorization': self.api} | ||
# request | ||
response = requests.get('https://statistics-api.wildberries.ru/api/v1/supplier/reportDetailByPeriod', | ||
headers=headers, | ||
params={"dateFrom":date_from, "dateTo":date_to, 'rrdid':0}) | ||
if data_type == 'json': | ||
jdata = json.loads(response.text) | ||
return jdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name='berrylib', | ||
packages=find_packages(), | ||
version='0.0.1', | ||
description='Wildberries api requests library', | ||
install_requires=['requests'], | ||
author='Nikolai Baakh', | ||
setup_requires=['pytest-runner'], | ||
tests_require=['pytest==4.4.1'], | ||
test_suite='tests' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import berrylib | ||
|
||
me = berrylib.WbShop('api') |
Empty file.