{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Checklists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from api import BigApi\n",
    "\n",
    "BigApi.init(\".admin.env\")\n",
    "BigApi.adminLogin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = BigApi.adminGet(f\"/admin/shop/orders/sync\");\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = BigApi.adminGet(\"/admin/shop/orders/report\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = BigApi.adminGet(\"/admin/shop/orders/checklist\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = BigApi.adminGet(\"/admin/inventory/sync\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "status = \"InStock\"\n",
    "type = \"BigscreenBeyondV1\"\n",
    "data = BigApi.adminGet(f\"/admin/inventory/items?status={status}&type={type}\")\n",
    "\n",
    "# Convert data to json and write to file\n",
    "# Use a file name with the date and time in it\n",
    "import datetime\n",
    "now = datetime.datetime.now()\n",
    "filename = f\"inventory_{status}_{type}_{now.strftime('%Y-%m-%d_%H-%M-%S')}.json\"\n",
    "with open(filename, \"w\") as f:\n",
    "    f.write(json.dumps(data, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = BigApi.adminGet(\"/admin/fabricator/jobs/report\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = BigApi.adminGet(\"/admin/fabricator/jobs/report2\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = BigApi.adminGet(\"/admin/fabricator/scan_requests/repair?dryRun=1\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get all the pending scan requests and report the age of the individual request.\n",
    "import time\n",
    "\n",
    "cursorId = None\n",
    "scan_requests = []\n",
    "while(True):\n",
    "    url = \"/admin/fabricator/scan_requests?limit=200\"\n",
    "    if cursorId != None:\n",
    "        url += \"&cursorId=\" + cursorId\n",
    "    data = BigApi.adminGet(url)\n",
    "    scan_requests.extend(data[\"items\"])\n",
    "\n",
    "    if \"cursorId\" not in data or len(data[\"items\"]) < 25:\n",
    "        break\n",
    "    else:\n",
    "        cursorId = data[\"cursorId\"]\n",
    "\n",
    "awaiting = 0\n",
    "for scan_request in scan_requests:\n",
    "    if (scan_request[\"scanRequestState\"] == 3):\n",
    "        createdAt = scan_request[\"createdAt\"]\n",
    "        now = int(time.time() * 1000)\n",
    "        diff = now - createdAt\n",
    "        id = scan_request[\"id\"]\n",
    "        print(f\"ID: {id} - {diff / (60 * 60 * 24 * 1000)} days ago\")\n",
    "\n",
    "awaiting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import base64\n",
    "import os\n",
    "\n",
    "# Generate 18 random bytes. Why 18? Because 18 bytes become 24 characters when encoded in base64.\n",
    "random_bytes = os.urandom(32)\n",
    "\n",
    "# Encode the bytes in a URL-safe base64\n",
    "encoded_string = base64.urlsafe_b64encode(random_bytes).decode('utf-8')\n",
    "\n",
    "print(encoded_string)"
   ]
  }
 ],
 "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.10.11"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "369f2c481f4da34e4445cda3fffd2e751bd1c4d706f27375911949ba6bb62e1c"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
