{
 "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": [
    "ScanVerificationFailed = 101\n",
    "queryResult = BigApi.adminGet(f\"/admin/fabricator/jobs?jobState={ScanVerificationFailed}\")\n",
    "\n",
    "for job in queryResult[\"items\"]:\n",
    "    if job[\"bigOrderId\"] is None:\n",
    "        continue\n",
    "\n",
    "    bigOrderId = job[\"bigOrderId\"]\n",
    "    try:\n",
    "        bigOrder = BigApi.adminGet(f\"/admin/shop/order/{bigOrderId}\")\n",
    "    except:\n",
    "        print(f\"Failed to get bigOrder {bigOrderId}\")\n",
    "        continue\n",
    "\n",
    "    if bigOrder[\"shopifyOrderSnapshot\"][\"shipping_address\"][\"country_code\"] == \"US\":\n",
    "        # If the bigOrder[\"currentLineItems\"] has a line item where \"type\" is \"PrescriptionLenses\" then bail out\n",
    "        if any(lineItem[\"type\"] == \"PrescriptionLenses\" for lineItem in bigOrder[\"currentLineItems\"]):\n",
    "            continue\n",
    "        print(f\"Found bigOrder {bigOrderId} with no prescription lenses\")\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bigOrderId=\"(Unknown)\"\n",
    "queryResult = BigApi.adminGet(f\"/admin/fabricator/jobs\")\n",
    "\n",
    "jobIds = []\n",
    "\n",
    "for job in queryResult[\"items\"]:\n",
    "    if job[\"bigOrderId\"] == bigOrderId:\n",
    "        jobIds.append(job[\"id\"])\n",
    "\n",
    "print(f\"Found {len(jobIds)} jobs for bigOrder {bigOrderId}\")"
   ]
  }
 ],
 "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
}
