file:///c%3A/Users/decid/Documents/projects/bigscreen/big-notebooks/019.customerService.ipynb {"mtime":1701658128134,"ctime":1701657602864,"size":6551,"etag":"3bimh6hdb6pa","orphaned":false,"typeId":"notebook/jupyter-notebook"}
{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Checklists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    }
   ],
   "source": [
    "# login\n",
    "# import imp\n",
    "import api\n",
    "# imp.reload(api)\n",
    "from api import BigApi\n",
    "\n",
    "BigApi.init(\".admin.env\")\n",
    "BigApi.adminLogin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# show scan request info\n",
    "# scanRequestID = ''\n",
    "# data = BigApi.adminGet(f\"/admin/fabricator/scan_request/{scanRequestID}\")\n",
    "\n",
    "# delete item from inventory\n",
    "itemID = 'qU7rpIKn9xPibjVw4c7mPgN18dI'\n",
    "data = BigApi.adminDel(f\"/admin/shop/order/{itemID}\")\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# populate schemas\n",
    "\n",
    "schemas = BigApi.adminGet(f\"/admin/fabricator/schemas2\")\n",
    "schemas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change IPD for a given BigOrder ID\n",
    "bigOrderID = ''\n",
    "newIPD = 62\n",
    "\n",
    "data = BigApi.adminPut(f\"/admin/shop/order/{bigOrderID}\", {\n",
    "                \"action\": \"AdminOverrideIPD\",\n",
    "                \"ipd\": newIPD\n",
    "            })\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change priority for given BigOrder ID\n",
    "bigOrderId = 'PUzzWuGmB0O3UY6c'\n",
    "newPriority = \"90\"\n",
    "data = BigApi.adminPut(f\"/admin/shop/order/{bigOrderId}\", {\"action\": \"AdminSetPriority\", \"priority\": newPriority})\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "status code should be 200 (actual: 422)\n"
     ]
    },
    {
     "ename": "AssertionError",
     "evalue": "status code should be 200 (actual: 422)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAssertionError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32mc:\\Users\\decid\\Documents\\projects\\bigscreen\\big-notebooks\\019.customerService.ipynb Cell 7\u001b[0m line \u001b[0;36m4\n\u001b[0;32m      <a href='vscode-notebook-cell:/c%3A/Users/decid/Documents/projects/bigscreen/big-notebooks/019.customerService.ipynb#X14sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m jobId \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mPUzzWuGmB0O3UY6c\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m      <a href='vscode-notebook-cell:/c%3A/Users/decid/Documents/projects/bigscreen/big-notebooks/019.customerService.ipynb#X14sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m newPriority \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m75\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/decid/Documents/projects/bigscreen/big-notebooks/019.customerService.ipynb#X14sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m data \u001b[39m=\u001b[39m BigApi\u001b[39m.\u001b[39;49madminPut(\u001b[39mf\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m/admin/fabricator/job/\u001b[39;49m\u001b[39m{\u001b[39;49;00mjobId\u001b[39m}\u001b[39;49;00m\u001b[39m\"\u001b[39;49m, {\u001b[39m\"\u001b[39;49m\u001b[39maction\u001b[39;49m\u001b[39m\"\u001b[39;49m: \u001b[39m\"\u001b[39;49m\u001b[39mAdminSetPriority\u001b[39;49m\u001b[39m\"\u001b[39;49m, \u001b[39m\"\u001b[39;49m\u001b[39mpriority\u001b[39;49m\u001b[39m\"\u001b[39;49m: newPriority})\n\u001b[0;32m      <a href='vscode-notebook-cell:/c%3A/Users/decid/Documents/projects/bigscreen/big-notebooks/019.customerService.ipynb#X14sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m data\n",
      "File \u001b[1;32mc:\\Users\\decid\\Documents\\projects\\bigscreen\\big-notebooks\\api.py:280\u001b[0m, in \u001b[0;36mBigApi.adminPut\u001b[1;34m(url, payload)\u001b[0m\n\u001b[0;32m    278\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m    279\u001b[0m     \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mstatus code should be 200 (actual: \u001b[39m\u001b[39m{\u001b[39;00mr\u001b[39m.\u001b[39mstatus_code\u001b[39m}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m--> 280\u001b[0m     \u001b[39massert\u001b[39;00m r\u001b[39m.\u001b[39mstatus_code \u001b[39m==\u001b[39m \u001b[39m200\u001b[39m, \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mstatus code should be 200 (actual: \u001b[39m\u001b[39m{\u001b[39;00mr\u001b[39m.\u001b[39mstatus_code\u001b[39m}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m\"\u001b[39m\n",
      "\u001b[1;31mAssertionError\u001b[0m: status code should be 200 (actual: 422)"
     ]
    }
   ],
   "source": [
    "# change priority for given Job ID\n",
    "jobId = 'PUzzWuGmB0O3UY6c'\n",
    "newPriority = \"75\"\n",
    "data = BigApi.adminPut(f\"/admin/fabricator/job/{jobId}\", {\"action\": \"AdminSetPriority\", \"priority\": newPriority})\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 1. SET email address or Shopify order name for the cell below\n",
    "from api import BigApi\n",
    "\n",
    "searchTerm = 'envizodot@gmail.com' ### CHANGE THIS TO THE EMAIL OR SHOPIFY ORDER NAME YOU WANT TO SEARCH FOR ###\n",
    "\n",
    "\n",
    "BigApi.init(\".admin.env\")\n",
    "BigApi.adminLogin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 2. RESEND scan result email for search term defined above\n",
    "import os\n",
    "import json\n",
    "\n",
    "# function that accepts a list of properties formatted {name: 'name', value: 'value'} and accepts a name and returns the value\n",
    "def getSiblingProp(props, findVal, findKey = 'name', returnKey = 'value'):\n",
    "  for prop in props:\n",
    "    if(findVal in prop[findKey]):\n",
    "      return prop[returnKey]\n",
    "  return None\n",
    "\n",
    "outputDir = 'C:/Users/decid/Documents/Bigscreen/LENS_ORDERS'\n",
    "beyondOrdersFile = f'{outputDir}/beyondOrders.json'\n",
    "\n",
    "\n",
    "# If file exists, read it. If not, quit\n",
    "if os.path.exists(beyondOrdersFile):\n",
    "    try:\n",
    "        with open(beyondOrdersFile, 'r') as file:\n",
    "            beyondOrdersByEmail = json.load(file)\n",
    "            print(f\"Library of Beyond orders loaded from {beyondOrdersFile}.\") #debug\n",
    "        # print('Original data:', beyondOrdersByEmail) #debug\n",
    "    except json.JSONDecodeError:\n",
    "        assert False, f\"Error: {beyondOrdersFile} contains invalid JSON. Please check formatting.\"\n",
    "else:\n",
    "    assert False, f\"{beyondOrdersFile} does not exist. Populate and write it using the cell in rxLensFulfillment.ipynb\"\n",
    "\n",
    "\n",
    "bigOrderID = getSiblingProp(beyondOrdersByEmail, searchTerm, 'email' if('@' in searchTerm) else 'orderName', 'bigOrderId')\n",
    "if(bigOrderID == None or bigOrderID == ''):\n",
    "  assert False, f\"Could not find BigOrder ID for search term \\\"{searchTerm}\\\".\"\n",
    "# bigOrderID #debug\n",
    "\n",
    "try:\n",
    "  data = BigApi.adminPut(f\"/admin/shop/order/{bigOrderID}\", {\"action\":\"ResendScanResultEmail\"})\n",
    "except json.JSONDecodeError:\n",
    "  assert False, f\"さいこうだ！！ We got the JSON decode error for BigOrder {bigOrderID}. So it probably worked!\"\n",
    "except Exception as e:\n",
    "  assert False, f\"Error requesting scan confirmation email: {e}\"\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# run checklist on the given BigOrder ID -- will generate a job if scan request state is \"READYFORFABRICATOR\"\n",
    "bigOrderID = ''\n",
    "data = BigApi.adminGet(f\"/admin/shop/order/{bigOrderID}/checklist\")\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# find cushion inventory index for given job ID\n",
    "import hashlib\n",
    "\n",
    "jobId = 'Qn0MOrW0hxjewVqr'\n",
    "\n",
    "def hash_to_three_digits_md5(input_string):\n",
    "    hash_object = hashlib.md5(input_string.encode())\n",
    "    return (int(hash_object.hexdigest(), 16) % 1000)/10\n",
    "\n",
    "hash_to_three_digits_md5(jobId)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# find job with given nfcTagId\n",
    "nfcTagId = ''\n",
    "data = BigApi.adminPost(f\"/admin/fabricator/jobs\", {\"nfcTagId\":nfcTagId})\n",
    "\n",
    "data"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.0"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "369f2c481f4da34e4445cda3fffd2e751bd1c4d706f27375911949ba6bb62e1c"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
