{
 "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": [
    "import json\n",
    "\n",
    "f = open(\"./lensOnlyOrderIds.json\")\n",
    "lensOnlyOrderIds = json.load(f)[\"orderIds\"]\n",
    "print(lensOnlyOrderIds)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "f = open(\"./lensOnlyOrderIds.json\")\n",
    "lensOnlyOrderIds = json.load(f)[\"orderIds\"]\n",
    "\n",
    "def containsBeyondItem(shopifyOrder):\n",
    "    for lineItem in shopifyOrder[\"line_items\"]:\n",
    "        if lineItem[\"product_id\"] == 7693929054425:\n",
    "            return True\n",
    "    return False\n",
    "\n",
    "for orderId in lensOnlyOrderIds:\n",
    "    # escape the value for url string\n",
    "    escapedOrderId = orderId.replace(\"#\", \"%23\")\n",
    "    url = f\"/admin/shop/shopify_orders?search={escapedOrderId}\"\n",
    "    result = BigApi.adminGet(url)\n",
    "    assert len(result[\"orders\"]) == 1\n",
    "    shopifyOrder = result[\"orders\"][0][\"shopifyOrder\"]\n",
    "\n",
    "    # check if bigOrder exists in order\n",
    "    if result[\"orders\"][0].get(\"bigOrder\"):\n",
    "        continue\n",
    "    if containsBeyondItem(shopifyOrder) == True:\n",
    "        continue\n",
    "\n",
    "    data = BigApi.adminPost(\"/admin/shop/order\", {\"shopifyOrderId\": shopifyOrder[\"id\"]})\n",
    "    bigOrderId = data[\"id\"]\n",
    "\n",
    "    data = BigApi.adminGet(f\"/admin/shop/order/{bigOrderId}\")\n",
    "    assert data[\"id\"] == bigOrderId, f\"bigOrderId should be {bigOrderId} (actual: {data['id']})\"\n",
    "    \n",
    "    print(f\"orderId: {orderId}\")"
   ]
  }
 ],
 "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
}
