mirror of
https://codeberg.org/plate/libssa.git
synced 2026-04-17 01:05:24 -04:00
Sainsbury's SmartShop Python lib
- Python 100%
| libssa | ||
| .gitignore | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
libssa
Python wrapper for the Sainsbury's SmartShop API.
Goals:
- Allow API interaction
Non-goals:
- Be identical to the official app(s)
- Provide a full data model
- 100% coverage - I add endpoints as I use them
Also, this is partly written by decompiling the app to port authentication code. If that's legally hairy or something, find another library.
Installation
pip install git+https://codeberg.org/plate/libssa
Usage
Use the Client class:
from libssa.client import Client
c = Client()
This defaults to the Android client. You can also supply a custom client ID and key (likely not needed):
from libssa import constants
c = Client(client_id=constants.HANDSET_CLIENT_ID, rsa_key=constants.HANDSET_KEY)
c = Client(client_id="ss_whatever_mobile_1k", rsa_key="-----BEGIN RSA PUBLIC KEY-----...")
Then you can log in as needed:
# Nectar grant type (use last 11 digits: 9623000 12345678900)
# 00000000063 is a real card you can test with!
c.login("nectar_card", nectar_card="00000000063")
# Username/password grant type
c.login("password", username="username@example.com", password="password")
Please refer to the code for other ways to authenticate.
Starting a shop returns a Shop (libssa.shop.Shop) object:
s = c.create_shop("1234") # start shopping at your store id
s.add_item("123456", 10) # add 10 of this item
s.finish() # finish the shop
s.move_to_pos("12") # send it to POS 12
When a request fails, you want to catch libssa.errors.RequestError, which has the
status_code and response (requests.Response) properties.