{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from api import BigApi\n",
    "BigApi.init(\".admin.env\")\n",
    "BigApi.adminLogin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "countryCode = \"US\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "states = [\"WaitingForInventory\", \"WaitingForManufacturing\", \"WaitingForScanRequest\"]\n",
    "\n",
    "bigOrders = []\n",
    "\n",
    "for state in states:\n",
    "    queryResult = BigApi.adminGet(f\"/admin/shop/orders?state={state}&countryCode={countryCode}&origin=Shopify&shopifyMaxCreatedAt=2024-01-01T00%3A00%3A00-08%3A00\")\n",
    "    bigOrders.extend(queryResult[\"items\"])\n",
    "    print(queryResult[\"count\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ipds = {}\n",
    "for bigOrder in bigOrders:\n",
    "    if any(lineItem[\"shopifySku\"] == \"BS1B00\" for lineItem in bigOrder[\"currentLineItems\"]):\n",
    "        if ipds.get(bigOrder[\"ipd\"]) is None:\n",
    "            ipds[bigOrder[\"ipd\"]] = 0\n",
    "        ipds[bigOrder[\"ipd\"]] = ipds[bigOrder[\"ipd\"]] + 1\n",
    "\n",
    "sorted_keys = sorted(ipds.keys())\n",
    "for key in sorted_keys:\n",
    "    print(f\"{key}\\t{ipds[key]}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "states = [\"Shipped\", \"Cancelled\"]\n",
    "\n",
    "for state in states:\n",
    "    queryResult = BigApi.adminGet(f\"/admin/shop/orders?state={state}&countryCode={countryCode}&origin=Shopify&shopifyMaxCreatedAt=2023-09-01T00%3A00%3A00-08%3A00\")\n",
    "    print(queryResult[\"count\"])"
   ]
  }
 ],
 "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"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
