inventory database management functions
Project description
Project name here
Summary description here.
This file will become your README and also the index of your documentation.
Install
pip install villaInvDatabase
How to use
interact with a database hosted in dynamodb
import os
os.environ['DATABASE_TABLE_NAME'] = 'inventory-database-dev-manual'
os.environ['REGION'] = 'ap-southeast-1'
os.environ['INVENTORY_BUCKET_NAME'] = 'inventory-bucket-dev-manual'
os.environ['INPUT_BUCKET_NAME'] = 'input-bucket-dev-manual'
# os.environ['DAX_ENDPOINT'] = None
REGION = 'ap-southeast-1'
INVENTORY_BUCKET_NAME = os.environ['INVENTORY_BUCKET_NAME']
INPUT_BUCKET_NAME = os.environ['INPUT_BUCKET_NAME']
from villaInvDatabase.database import Database
dax endpoint missing
sampleInput = [
{ 'ib_prcode': '0000009', 'ib_brcode': '1000', 'ib_cf_qty': '50', 'new_ib_vs_stock_cv': '27' },
{ 'ib_prcode': '0000002', 'ib_brcode': '1000', 'ib_cf_qty': '35', 'new_ib_vs_stock_cv': '33' }
]
%%time
#update
Database.dumpToS3(user=USER, pw = PW)
CPU times: user 44.5 ms, sys: 18.4 ms, total: 62.9 ms
Wall time: 296 ms
{'newDataSaved': False,
'numberOfProducts': 0,
'message': 'no changes to database'}
%%time
Database.splitBranches(bucket = INVENTORY_BUCKET_NAME, user=USER, pw=PW)
CPU times: user 15.2 s, sys: 405 ms, total: 15.6 s
Wall time: 26.9 s
{'success': 32, 'failure': 0, 'errorMessage': []}
Save using Standard
Database.updateLambdaInput(sampleInput)
{'success': 0, 'failure': 0, 'failureMessage': []}
Save using s3
inputKeyName = 'input-data-name'
saveResult = S3.save(key=inputKeyName,
objectToSave = sampleInput ,
bucket = INPUT_BUCKET_NAME,
user = USER,
pw = PW,
accelerate = False)
logging.info('test input data saved to s3')
updateResult = Database.updateS3Input(
inputBucketName=INPUT_BUCKET_NAME, key= inputKeyName,
user = USER, pw = PW)
logging.info(f's3 save result is {saveResult} update result is {updateResult}')
Query test
Product Query
sampleQueryInput = {
'ib_prcode': '0000002'
}
Database.singleProductQuery(sampleQueryInput)
{"ib_prcode": "0000002", "1000": {"ib_cf_qty": 35, "new_ib_bs_stock_cv": 33, "lastUpdate": 1601530923.436074}, "lastUpdate": 1601530923.436074}
Branch Query
from s3bz.s3bz import Requests
branchURL = Database.branchQuery('1000', bucket = INVENTORY_BUCKET_NAME, user=USER, pw=PW)
print(branchURL)
next(iter(Requests.getContentFromUrl(branchURL).items()))
https://inventory-bucket-dev-manual.s3-accelerate.amazonaws.com/1000?AWSAccessKeyId=AKIAVX4Z5TKDVOBZ6C54&Signature=JAyklUViFbIzm%2FHZe0HvjEZDwCA%3D&Expires=1602489345
('0000009',
{'ib_cf_qty': 50, 'new_ib_bs_stock_cv': 27, 'lastUpdate': 1602338504.869655})
AllQuery
from s3bz.s3bz import Requests
branchURL = Database.allQuery(bucket = INVENTORY_BUCKET_NAME, user=USER, pw=PW)
print(branchURL)
next(iter(Requests.getContentFromUrl(branchURL).items()))
https://inventory-bucket-dev-manual.s3-accelerate.amazonaws.com/allData?AWSAccessKeyId=AKIAVX4Z5TKDVOBZ6C54&Signature=QqfqWUnB641lTOsGi5QKZCrRDrM%3D&Expires=1602489345
('0000009',
{'ib_prcode': '0000009',
'1000': {'ib_cf_qty': 50,
'new_ib_bs_stock_cv': 27,
'lastUpdate': 1602338504.869655},
'lastUpdate': 1602338504.869655})
costPer100ms = 0.0000016667
costPerMs = costPer100ms / 100
timePerCallS = 40
timePerCallMs = timePerCallS * 1000
costPerCall = costPerMs * timePerCallMs
callsPerDay = 60 * 24 /10
costPerDay = callsPerDay * costPerCall
costPerDay * 33
3.16806336
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
villaInvDatabase-0.0.14.tar.gz
(18.0 kB
view hashes)
Built Distribution
Close
Hashes for villaInvDatabase-0.0.14-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 329ec21f9a673c95f034a35b6632f2aff530c0a2971a280ebb9cfda0e1637797 |
|
MD5 | 5ee20df813c7e67bc902c828a44467d4 |
|
BLAKE2b-256 | 8f209bee409a437128ffa6953973b0239e7b000d19403217dfca3c4c5c40e78b |