Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Created July 27, 2021 06:55
Show Gist options
  • Save thanakijwanavit/7a07378577c22762ff2c599fbd3d727e to your computer and use it in GitHub Desktop.
Save thanakijwanavit/7a07378577c22762ff2c599fbd3d727e to your computer and use it in GitHub Desktop.
getInventoryVilla
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "getInventoryVilla",
"private_outputs": true,
"provenance": [],
"collapsed_sections": [],
"mount_file_id": "1yRUL_-DphiXa7VoNS6UWAqMOuRYka8rU",
"authorship_tag": "ABX9TyOLsxMIGS5RG8HVrwZUPcBU",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/thanakijwanavit/7a07378577c22762ff2c599fbd3d727e/getinventoryvilla.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "ApcFjD9RsWn_"
},
"source": [
"!pip install -q nicHelper"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "f8KhKzUksFSU"
},
"source": [
"from nicHelper.colab import autoSetupAws\n",
"from getpass import getpass\n",
"path = '/content/drive/MyDrive/.awsKey'\n",
"\n",
"autoSetupAws(path=path,\n",
" password = getpass('enter your password').encode(),\n",
" region='ap-southeast-1' )"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "ATkOyaYgsUv6"
},
"source": [
"from typing import List\n",
"import pandas as pd\n",
"import requests, json"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "pmhav2I9s_m1"
},
"source": [
"def getProducts(brcode:str, iprcodes:List[int]):\n",
" invApi = '2y9nzxkuyk'\n",
" url = f'https://{invApi}.execute-api.ap-southeast-1.amazonaws.com/Prod/branch'\n",
" payload = {\n",
" \"brcode\": brcode,\n",
" \"cprcodes\": []\n",
" } \n",
" r = requests.post(url, json=payload)\n",
" r2 = requests.get(r.json()['url'])\n",
" df = pd.read_json(json.dumps(r2.json()), orient='split')\n",
" if iprcodes:\n",
" return df[df.iprcode.isin(iprcodes)]\n",
" return df\n",
" "
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "5OugKugbt5IU"
},
"source": [
"getProducts(brcode='1000', iprcodes=[49859]).head()"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "a8ZSCRhBut79"
},
"source": [
"getProducts(brcode='1000', iprcodes=[]).head()"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "LLYxKfWZu2FV"
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment