Skip to content

Commit

Permalink
First function
Browse files Browse the repository at this point in the history
  • Loading branch information
BaakhOfficial committed Nov 30, 2023
1 parent f5f92a6 commit e898885
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions berrylib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .wb_shop import WbShop
38 changes: 38 additions & 0 deletions berrylib/wb_shop.py
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
13 changes: 13 additions & 0 deletions setup.py
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'
)
3 changes: 3 additions & 0 deletions tests/WbShop_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import berrylib

me = berrylib.WbShop('api')
Empty file added tests/__init__.py
Empty file.

0 comments on commit e898885

Please sign in to comment.