Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

villaProductDatabase-0.0.48.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

villaProductDatabase-0.0.48-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file villaProductDatabase-0.0.48.tar.gz.

File metadata

  • Download URL: villaProductDatabase-0.0.48.tar.gz
  • Upload date:
  • Size: 18.7 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

Hashes for villaProductDatabase-0.0.48.tar.gz
Algorithm Hash digest
SHA256 a882d9eef083ae5df7d639b06cccbf04b6a68269f7ba1a1b5192883d5ea2bec0
MD5 1a9e86f44f41960c4a16c7420f7e5c82
BLAKE2b-256 2e333ea6bd352a36eb3c03d665a12b020c76610e9790ee2eb79a73ca900392fa

See more details on using hashes here.

File details

Details for the file villaProductDatabase-0.0.48-py3-none-any.whl.

File metadata

  • Download URL: villaProductDatabase-0.0.48-py3-none-any.whl
  • Upload date:
  • Size: 20.4 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

Hashes for villaProductDatabase-0.0.48-py3-none-any.whl
Algorithm Hash digest
SHA256 f2a4ebd324af4a7b06877b9487737615a87f685e0c60eaa1fc6284eb507d666c
MD5 d669abd20e3d3df1cb62a9ae49d2e32d
BLAKE2b-256 853dd800a17b80d2118ca058922eb6fd3012f11fbd18379a7c7050e213bfc8bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page