product database management functions
Project description
villa inventory database module
Summary description here.
This file will become your README and also the index of your documentation.
Install
pip install villaProductDatabase
How to use
in lambda function, simply import and declare in your app.py
from villaProductDatabase import database
from awsSchema.apigateway import Response, Event
from s3bz.s3bz import S3
import json
lambdaDumpToS3 = database.lambdaDumpToS3
lambdaUpdateProduct = database.lambdaUpdateProduct
lambdaUpdateS3 = database.lambdaUpdateS3
lambdaSingleQuery = database.lambdaSingleQuery
lambdaAllQuery = database.lambdaAllQuery
lambdaListQuery = database.lambdaProductsFromList
# tests
sampleProducts = [{'cprcode': '0171670', 'iprcode': '0171670', 'oprcode': '0171670', 'ordertype': 'Y', 'pr_abb': 'JIRAPAT YOUNG KALE 2', 'pr_active': 'Y', 'pr_cgcode': '05', 'pr_code': '0171670', 'pr_dpcode': '19', 'pr_engname': 'JIRAPAT YOUNG KALE 200 G.', 'pr_ggcode': '057', 'pr_market': 'JIRAPAT ยอดคะน้า 200 G.', 'pr_name': 'JIRAPAT ยอดคะน้า 200 G.', 'pr_puqty': '1', 'pr_sa_method': '1', 'pr_sucode1': 'CM845 ', 'pr_suref3': 'A', 'prtype': 'I', 'psqty': '1', 'pstype': '1'}, {'cprcode': '0235141', 'iprcode': '0235141', 'oprcode': '0235141', 'ordertype': 'Y', 'pr_abb': 'EEBOO-PZCT3-PUZZLE', 'pr_active': 'Y', 'pr_cgcode': '08', 'pr_code': '0235141', 'pr_dpcode': '19', 'pr_engname': 'EEBOO,ANIMAL COUNTING PUZZLE_3ED,PZCT3', 'pr_ggcode': '113', 'pr_market': 'eeboo,PUZZLE-PZCT3', 'pr_name': 'EEBOO-PZCT3-ตัวต่อนับเลข ANIMAL COUNTING_3ED', 'pr_puqty': '1', 'pr_sa_method': '1', 'pr_sucode1': 'CM1979 ', 'pr_suref3': 'A', 'prtype': 'I', 'psqty': '1', 'pstype': '1'}, {'cprcode': '0217153', 'iprcode': '0217153', 'oprcode': '0217153', 'ordertype': 'Y', 'pr_abb': 'COCOA LOCO MILK CHOC', 'pr_active': 'Y', 'pr_cgcode': '98', 'pr_code': '0217153', 'pr_dpcode': '28', 'pr_engname': 'COCOA LOCO MILK CHOCOLATE OWL LOLLY 26G.', 'pr_ggcode': '003', 'pr_market': 'COCOA LOCO MILK CHOCOLATE OWL', 'pr_name': 'COCOA LOCO MILK CHOCOLATE OWL LOLLY 26G.', 'pr_puqty': '24', 'pr_sa_method': '1', 'pr_sucode1': 'F1222 ', 'pr_suref3': 'S', 'prtype': 'I', 'psqty': '1', 'pstype': '1'}, {'cprcode': '0182223', 'iprcode': '0182223', 'oprcode': '0182223', 'ordertype': 'Y', 'pr_abb': 'CIRIO PIZZASSIMO 400', 'pr_active': 'Y', 'pr_cgcode': '06', 'pr_code': '0182223', 'pr_dpcode': '06', 'pr_engname': 'CIRIO PIZZASSIMO 400G.', 'pr_ggcode': '004', 'pr_market': 'CIRIO ซอสทำพิซซ่า 400 G.', 'pr_name': 'CIRIO ซอสทำพิซซ่า 400 G.', 'pr_puqty': '12', 'pr_sa_method': '1', 'pr_sucode1': '2589 ', 'pr_suref3': 'C', 'prtype': 'I', 'psqty': '1', 'pstype': '1'}, {'cprcode': '0124461', 'iprcode': '0124461', 'oprcode': '0124461', 'ordertype': 'Y', 'pr_abb': 'NEW CHOICE LYCHEE', 'pr_active': 'Y', 'pr_cgcode': '02', 'pr_code': '0124461', 'pr_dpcode': '02', 'pr_engname': 'NEW CHOICE LYCHEE', 'pr_ggcode': '003', 'pr_market': 'NEW CHOICE กลิ่นลิ้นจี่', 'pr_name': 'NEW CHOICE กลิ่นลิ้นจี่', 'pr_puqty': '12', 'pr_sa_method': '1', 'pr_sucode1': '695 ', 'pr_suref3': 'A', 'prtype': 'I', 'psqty': '1', 'pstype': '1'}]
dump to s3
# test dump to s3
result = Response.fromDict(lambdaDumpToS3('','')).body['result']
print(result)
saved 5 products
update standard
# test saving products
event = {'body': json.dumps({ 'products': sampleProducts })}
result = Response.fromDict(lambdaUpdateProduct(event ,'')).body
print(result)
{'success': 0, 'failure': 0, 'skipped': 5, 'failureMessage': [], 'timetaken': 191.805}
update s3
# test saving using s3
inputKeyName = 'input-data-name'
saveResult = S3.save(key=inputKeyName,
objectToSave = sampleProducts ,
bucket = os.environ['INPUT_BUCKET_NAME'],
user = os.environ['USER'],
pw = os.environ['PW'],
accelerate = True)
event = {'body': json.dumps({'key': inputKeyName})}
lambdaUpdateS3(event, '')
{'body': '{"success": 0, "failure": 0, "skipped": 5, "failureMessage": [], "timetaken": 187.84}',
'statusCode': 200,
'header': {}}
single query
sampleQueryInput = { 'iprcode': '0171670' }
event = Event(body = json.dumps(sampleQueryInput)).to_dict()
lambdaSingleQuery(event,'')
{'body': '{"cprcode": "0171670", "iprcode": "0171670", "oprcode": "0171670", "ordertype": "Y", "pr_abb": "JIRAPAT YOUNG KALE 2", "pr_active": "Y", "pr_cgcode": "05", "pr_code": "0171670", "pr_dpcode": "19", "pr_engname": "JIRAPAT YOUNG KALE 200 G.", "pr_ggcode": "057", "pr_market": "JIRAPAT \\u0e22\\u0e2d\\u0e14\\u0e04\\u0e30\\u0e19\\u0e49\\u0e32 200 G.", "pr_name": "JIRAPAT \\u0e22\\u0e2d\\u0e14\\u0e04\\u0e30\\u0e19\\u0e49\\u0e32 200 G.", "pr_puqty": "1", "pr_sa_method": "1", "pr_sucode1": "CM845", "pr_suref3": "A", "prtype": "I", "psqty": "1", "pstype": "1"}',
'statusCode': 200,
'header': {}}
All Query
from s3bz.s3bz import Requests
url = Response.fromDict(lambdaAllQuery('', '')).body['url']
result = Requests.getContentFromUrl(url)
print(f'received {len(list(result.keys()))} results, the first one is {next(iter(result.items()))}')
received 5 results, the first one is ('0217153', {'0217153': {'cprcode': '0217153', 'iprcode': '0217153', 'oprcode': '0217153', 'ordertype': 'Y', 'pr_abb': 'COCOA LOCO MILK CHOC', 'pr_active': 'Y', 'pr_cgcode': '98', 'pr_code': '0217153', 'pr_dpcode': '28', 'pr_engname': 'COCOA LOCO MILK CHOCOLATE OWL LOLLY 26G.', 'pr_ggcode': '003', 'pr_market': 'COCOA LOCO MILK CHOCOLATE OWL', 'pr_name': 'COCOA LOCO MILK CHOCOLATE OWL LOLLY 26G.', 'pr_puqty': '24', 'pr_sa_method': '1', 'pr_sucode1': 'F1222', 'pr_suref3': 'S', 'prtype': 'I', 'psqty': '1', 'pstype': '1'}})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file villaProductDatabase-0.0.50.tar.gz
.
File metadata
- Download URL: villaProductDatabase-0.0.50.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef198ee660590521473959ae2ad851fca84e54a3ad8054c61a6cb91ebab3d3e0 |
|
MD5 | e497a2831cbd9b7c415e880adc11e956 |
|
BLAKE2b-256 | 7ca01fce115a2daeb5d318ec4d78f552ef3910386cd81e13dd6badc1b0e1778b |
File details
Details for the file villaProductDatabase-0.0.50-py3-none-any.whl
.
File metadata
- Download URL: villaProductDatabase-0.0.50-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e197562c17b13b7ce53538b1ef888e3bf0af580f274b239482c0f730d18ea4a |
|
MD5 | 3b875a05c8afd9324e141d6f570464b4 |
|
BLAKE2b-256 | fa41bf3ba04b44d163b0460cae3a4b606a116bb74030b6e59dc4e6d488408648 |