{ "cells": [ { "cell_type": "code", "execution_count": 53, "id": "1e4b01f8-321a-4dd7-a157-0c36a8f5142f", "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "import json\n", "import os\n", "import pprint\n", "\n", "import requests\n", "\n", "headers = {\n", " \"Authorization\": \"os.env(directus_token)\",\n", " \"Content-Type\": \"application/json\",\n", "}\n", "response = requests.get(\n", " \"https://cms.donavanaldrich.com/items/containers\", headers=headers\n", ")\n", "data = response.json()\n", "# pprint.pprint(items)\n", "items = data[\"data\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "1837f6a9-f3c2-4666-b21c-96ea2dd56a06", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 68, "id": "c0ff14db-e04c-45fa-ba43-6ba9bf56810e", "metadata": { "scrolled": true, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] } ], "source": [ "for item in items:\n", " raw = item[\"raw\"]\n", " name = raw[\"Name\"]\n", " image = raw[\"Config\"][\"Image\"]\n", " image = image.replace(\":latest\", \"\")\n", " name = name.replace(\"/\", \"\")\n", " try:\n", " item[\"ui_port\"] = raw[\"Config\"][\"Labels\"][\n", " \"traefik.http.services.\" + name + \".loadbalancer.server.port\"\n", " ]\n", " router = raw[\"Config\"][\"Labels\"][\"traefik.http.routers.\" + name + \".rule\"]\n", " item[\"host_url\"] = re.findall(\"Host\\(`([^\\)]+)`\\)\", router)\n", " item[\"docs_url\"] = raw[\"Config\"][\"Labels\"][\n", " \"org.opencontainers.image.documentation\"\n", " ]\n", " item[\"image_url\"] = raw[\"Config\"][\"Labels\"][\"org.opencontainers.image.source\"]\n", " except:\n", " foo = \"bar\"\n", " headers = {\n", " \"Authorization\": \"os.env(directus_token)\",\n", " \"Content-Type\": \"application/json\",\n", " }\n", " response = requests.patch(\n", " \"https://cms.donavanaldrich.com/items/containers/\" + str(item[\"id\"]),\n", " headers=headers,\n", " json=(item),\n", " )\n", " print(response)" ] }, { "cell_type": "code", "execution_count": 68, "id": "30fd3366-53f7-45e1-acd5-e5c1dd91ec14", "metadata": { "scrolled": true, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] } ], "source": [ "item = items[0]\n", " raw = item[\"raw\"]\n", " name = raw[\"Name\"]\n", " item[\"ui_port\"] = raw[\"Config\"][\"Labels\"][\n", " \"traefik.http.services.\" + name + \".loadbalancer.server.port\"\n", " ]\n", " \n", " router = raw[\"Config\"][\"Labels\"][\"traefik.http.routers.\" + name + \".rule\"]\n", " item[\"host_url\"] = re.findall(\"Host\\(`([^\\)]+)`\\)\", router)\n", " print(response)" ] }, { "cell_type": "code", "execution_count": null, "id": "3430aed0-6317-4889-bdaa-a2802edcc85a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "71e58084-525c-4ab2-ae31-431a8fbd5b49", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }