Sanitized more notebooks

master
Don Aldrich 3 years ago
parent eece64b6d7
commit 1b3ef09fbd
  1. 5
      data_converion/tomd.py
  2. 127
      data_transfer/Add Container Inventory to Directus.ipynb
  3. 326
      data_transfer/Add Homebrew Inventory to Directusa.ipynb
  4. 324
      data_transfer/Add Inventories to wiki.ipynb
  5. 198
      data_transfer/Add Linkace Inventory to Directus.ipynb
  6. 124
      data_transfer/Add traefic routers.ipynb
  7. 86
      data_transfer/Directus query.ipynb
  8. 128
      data_transfer/Wiki-js query.ipynb
  9. 1560
      templating/Dashmachine Config Template.ipynb
  10. 43
      templating/template.test
  11. 114
      webscraping/robot_framework/Untitled.ipynb

@ -0,0 +1,5 @@
import tomd
tomd.Tomd('<h1>h1</h1>').markdown
# or
tomd.convert('<h1>h1</h1>')

@ -0,0 +1,127 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "2bec1b04-f1ab-4165-a4ea-cc890cc9e5ec",
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install gql"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dca88210-18db-45ee-9949-7010b92dbae7",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import os\n",
"import pprint\n",
"\n",
"import requests\n",
"from gql import Client, gql\n",
"from gql.transport.requests import RequestsHTTPTransport\n",
"\n",
"cwd = os.getcwd()\n",
"print(cwd)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7374f89e-23f8-407d-967b-c76e7d6d93a2",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"with open(\"/home/jovyan/code/directus/docker.json\") as f:\n",
" scrubbed_records = json.load(f)\n",
"\n",
"# print(scrubbed_records[0])\n",
"item = scrubbed_records[0]\n",
"name = item[\"Name\"]\n",
"image = item[\"Config\"][\"Image\"]\n",
"# print(name)\n",
"# print(image)\n",
"image = image.replace(\":latest\", \"\")\n",
"name = name.replace(\"/\", \"\")\n",
"print(name)\n",
"print(image)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f2b300a9-f7c0-4863-9696-29e92e6cedc8",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"for x in scrubbed_records:\n",
" # pprint.pprint(x)\n",
" item = x\n",
" name = item[\"Name\"]\n",
" image = item[\"Config\"][\"Image\"]\n",
" image = image.replace(\":latest\", \"\")\n",
" name = name.replace(\"/\", \"\")\n",
" print(name)\n",
" print(image)\n",
" input_set = {\"id\": name, \"image\": image, \"name\": name, \"raw\": item}\n",
"\n",
" my_headers = {\n",
" \"Authorization\": os.getenv(directus_token),\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
" response = requests.post(\n",
" \"https://cms.donavanaldrich.com/items/containers\",\n",
" headers=my_headers,\n",
" json=(input_set),\n",
" )\n",
" print(response.json())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.13 64-bit",
"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.13"
},
"toc-autonumbering": false,
"toc-showcode": false,
"toc-showtags": false,
"vscode": {
"interpreter": {
"hash": "340e956ee656efd8fdfb480dc033c937d9b626f8b21073bd1b5aa2a469586ea6"
}
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,326 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "2bec1b04-f1ab-4165-a4ea-cc890cc9e5ec",
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install gql"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7374f89e-23f8-407d-967b-c76e7d6d93a2",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"import csv\n",
"\n",
"with open(\"/home/jovyan/code/directus/homebrew.txt\") as f:\n",
" reader = csv.reader(f)\n",
" for row in reader:\n",
" item = row[0]\n",
" print(item)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0367eee-e052-4184-b016-8ecb0dd1aa32",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"for x in scrubbed_records:\n",
" # pprint.pprint(x)\n",
" image = image.replace(\":latest\", \"\")\n",
" name = name.replace(\"/\", \"\")\n",
" data = x"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f2b300a9-f7c0-4863-9696-29e92e6cedc8",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"for x in scrubbed_records:\n",
" item = x\n",
" name = item[\"Name\"]\n",
" image = item[\"Config\"][\"Image\"]\n",
" image = image.replace(\":latest\", \"\")\n",
" name = name.replace(\"/\", \"\")\n",
" print(name)\n",
" print(image)\n",
" input_set = {\"id\": name, \"image\": image, \"name\": name, \"raw\": item}\n",
"\n",
" my_headers = {\n",
" \"Authorization\": \"os.env(directus_token)\",\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
" response = requests.post(\n",
" \"https://cms.donavanaldrich.com/items/containers\",\n",
" headers=my_headers,\n",
" json=(input_set),\n",
" )\n",
" print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4dc5471-3df9-4d52-865e-ca9202d472a3",
"metadata": {},
"outputs": [],
"source": [
"# https://formulae.brew.sh/api/cask.json"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "74566291-5fb8-455a-b674-03c0733c6700",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'appcast': None,\n",
" 'artifacts': [['0 A.D..app'],\n",
" {'signal': {},\n",
" 'trash': '~/Library/Saved Application '\n",
" 'State/com.wildfiregames.0ad.savedState'}],\n",
" 'auto_updates': None,\n",
" 'caveats': None,\n",
" 'conflicts_with': None,\n",
" 'container': None,\n",
" 'depends_on': {'macos': {'>=': ['10.12']}},\n",
" 'desc': 'Real-time strategy game',\n",
" 'full_token': '0-ad',\n",
" 'homepage': 'https://play0ad.com/',\n",
" 'installed': None,\n",
" 'name': ['0 A.D.'],\n",
" 'outdated': False,\n",
" 'sha256': 'd1a2073dee3435d8a78bf289206248c9ed6be5e17f4ba1ac8412caf6d0eae0b0',\n",
" 'tap': 'homebrew/cask',\n",
" 'token': '0-ad',\n",
" 'url': 'https://releases.wildfiregames.com/0ad-0.0.25b-alpha-osx64.dmg',\n",
" 'version': '0.0.25b-alpha',\n",
" 'versions': {}}\n"
]
}
],
"source": [
"import json\n",
"import os\n",
"import pprint\n",
"\n",
"import requests\n",
"\n",
"my_headers = {\"Content-Type\": \"application/json\"}\n",
"raw_casks = requests.get(\"https://formulae.brew.sh/api/cask.json\")\n",
"\n",
"casks = raw_casks.json()\n",
"\n",
"# pprint.pprint(casks[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b3f64e7-019a-4c21-9de2-5c84bd22640f",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"for cask in casks:\n",
" name = cask[\"name\"][0]\n",
" desc = cask[\"desc\"]\n",
" homepage = cask[\"homepage\"]\n",
" url = cask[\"url\"]\n",
" tap = cask[\"tap\"]\n",
" full_name = cask[\"full_token\"]\n",
" print(full_token)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1d6f86f0-91ab-4773-aba3-ace57852f9e4",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'raw' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_9736/2986828884.py\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mcategory\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"cask\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0minput_set\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"id\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mfull_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"description\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdesc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"homepage\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mhomepage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"tap\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtap\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"raw\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mraw\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"category\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mcategory\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m response = requests.post(\n\u001b[1;32m 14\u001b[0m \u001b[0;34m\"https://cms.donavanaldrich.com/items/all_homebrews\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'raw' is not defined"
]
}
],
"source": [
"my_headers = {\"Authorization\": \"os.env(directus_token)\", \"Content-Type\": \"application/json\"}\n",
"\n",
"for cask in casks:\n",
" name = cask[\"name\"][0]\n",
" desc = cask[\"desc\"]\n",
" homepage = cask[\"homepage\"]\n",
" url = cask[\"url\"]\n",
" tap = cask[\"tap\"]\n",
" full_name = cask[\"full_token\"]\n",
" category = \"cask\"\n",
" # raw\n",
"\n",
" input_set = {\n",
" \"id\": full_name,\n",
" \"description\": desc,\n",
" \"homepage\": homepage,\n",
" \"tap\": tap,\n",
" \"raw\": cask,\n",
" \"category\": category,\n",
" }\n",
" response = requests.post(\n",
" \"https://cms.donavanaldrich.com/items/all_homebrews\",\n",
" headers=my_headers,\n",
" json=(input_set),\n",
" )\n",
" print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ecab5d16-91a5-4a3d-9772-516410b8ce76",
"metadata": {},
"outputs": [],
"source": [
"# https://formulae.brew.sh/api/formula.json"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "762b9c4d-dbfb-45dc-a24f-ca1a3a3bbbcf",
"metadata": {},
"outputs": [],
"source": [
"my_headers = {\"Content-Type\": \"application/json\"}\n",
"raw_brews = requests.get(\"https://formulae.brew.sh/api/formula.json\")\n",
"\n",
"brews = raw_brews.json()\n",
"\n",
"pprint.pprint(brews[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9bb9a11e-4343-421c-820d-ef927e02532f",
"metadata": {},
"outputs": [],
"source": [
"for brew in brews:\n",
" name = brew[\"name\"]\n",
" desc = brew[\"desc\"]\n",
" homepage = brew[\"homepage\"]\n",
" url = brew[\"urls\"][\"stable\"][\"url\"]\n",
" tap = brew[\"tap\"]\n",
" full_name = brew[\"full_name\"]\n",
" print(urls)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9630a738-10ef-40a0-b666-097b0ab02c06",
"metadata": {},
"outputs": [],
"source": [
"my_headers = {\"Authorization\": \"os.env(directus_token)\", \"Content-Type\": \"application/json\"}\n",
"\n",
"for brew in brews:\n",
" name = brew[\"name\"]\n",
" desc = brew[\"desc\"]\n",
" homepage = brew[\"homepage\"]\n",
" url = brew[\"urls\"][\"stable\"][\"url\"]\n",
" tap = brew[\"tap\"]\n",
" full_name = brew[\"full_name\"]\n",
" category = \"brew\"\n",
"\n",
" input_set = {\n",
" \"id\": full_name,\n",
" \"description\": desc,\n",
" \"homepage\": homepage,\n",
" \"tap\": tap,\n",
" \"raw\": brew,\n",
" \"category\": category,\n",
" }\n",
" response = requests.post(\n",
" \"https://cms.donavanaldrich.com/items/all_homebrews\",\n",
" headers=my_headers,\n",
" json=(input_set),\n",
" )\n",
" print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b835d52d-88bd-49f5-a1e3-d2b3c56e4fb2",
"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"
},
"toc-autonumbering": false,
"toc-showcode": false,
"toc-showtags": false,
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,324 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "2bec1b04-f1ab-4165-a4ea-cc890cc9e5ec",
"metadata": {},
"outputs": [],
"source": [
"pip install gql"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dca88210-18db-45ee-9949-7010b92dbae7",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import os\n",
"import pprint\n",
"\n",
"import requests\n",
"from gql import Client, gql\n",
"from gql.transport.requests import RequestsHTTPTransport\n",
"\n",
"cwd = os.getcwd()\n",
"print(cwd)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "7374f89e-23f8-407d-967b-c76e7d6d93a2",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"active_workflow\n",
"automaticmode/active_workflow\n"
]
}
],
"source": [
"data_json = os.env(PATH)\n",
"\n",
"\n",
"with open(data_json) as f:\n",
" scrubbed_records = json.load(f)\n",
"\n",
"# print(scrubbed_records[0])\n",
"item = scrubbed_records[0]\n",
"name = item[\"Name\"]\n",
"image = item[\"Config\"][\"Image\"]\n",
"# print(name)\n",
"# print(image)\n",
"image = image.replace(\":latest\", \"\")\n",
"name = name.replace(\"/\", \"\")\n",
"print(name)\n",
"print(image)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0367eee-e052-4184-b016-8ecb0dd1aa32",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"for x in scrubbed_records:\n",
" # pprint.pprint(x)\n",
" image = image.replace(\":latest\", \"\")\n",
" name = name.replace(\"/\", \"\")\n",
" data = x"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f2b300a9-f7c0-4863-9696-29e92e6cedc8",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"for x in scrubbed_records:\n",
" # pprint.pprint(x)\n",
" item = x\n",
" name = item[\"Name\"]\n",
" image = item[\"Config\"][\"Image\"]\n",
" image = image.replace(\":latest\", \"\")\n",
" name = name.replace(\"/\", \"\")\n",
" print(name)\n",
" print(image)\n",
" input_set = {\"id\": name, \"image\": image, \"name\": name, \"raw\": item}\n",
"\n",
" my_headers = {\"Authorization\": \"os.env(directus_token)\", \"Content-Type\": \"application/json\"}\n",
" response = requests.post(\n",
" \"https://cms.donavanaldrich.com/items/containers\",\n",
" headers=my_headers,\n",
" json=(input_set),\n",
" )\n",
" print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "927fe89f-9660-4681-884b-f258fc669b88",
"metadata": {},
"outputs": [],
"source": [
"pip install gql[all] aiohttp\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "a4dc5471-3df9-4d52-865e-ca9202d472a3",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'RequestsHTTPTransport' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_7244/3689489481.py\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m sample_transport = RequestsHTTPTransport(\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"http://directus:8055/graphql\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0muse_json\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m headers={\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\"Content-type\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"application/json\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'RequestsHTTPTransport' is not defined"
]
}
],
"source": [
"\n",
"sample_transport = RequestsHTTPTransport(\n",
" url=\"http://directus:8055/graphql\",\n",
" use_json=True,\n",
" headers={\n",
" \"Content-type\": \"application/json\",\n",
" \"Authorization\": \"os.env(directus_token)\",\n",
" },\n",
" verify=True,\n",
" retries=3,\n",
")\n",
"\n",
"client = Client(\n",
" transport=sample_transport,\n",
" fetch_schema_from_transport=True,\n",
")\n",
"\n",
"query = gql(\n",
" '''\n",
" query {\n",
" pages {\n",
" single(id: 3) {\n",
" id\n",
" path\n",
" locale\n",
" title\n",
" description\n",
" contentType\n",
" isPublished\n",
" isPrivate\n",
" privateNS\n",
" createdAt\n",
" updatedAt\n",
" }\n",
" }\n",
" }\n",
"'''\n",
")\n",
"\n",
"# params = { \"title\": article_attributes_data-posted-on }\n",
"\n",
"result = client.execute(query, variable_values=params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "48935cc6-c7c7-43f7-9fb7-c34bd457c903",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"import asyncio\n",
"\n",
"from gql import gql, Client\n",
"from gql.transport.aiohttp import AIOHTTPTransport\n",
"\n",
"transport = AIOHTTPTransport(\n",
" url=\"http://wiki:3000/graphql\",\n",
" headers={\n",
" \"Content-type\": \"application/json\",\n",
" \"Authorization\": \"os.env(directus_token)\",\n",
" },\n",
")\n",
"\n",
"# Create a GraphQL client using the defined transport\n",
"# client = Client(transport=transport, fetch_schema_from_transport=True)\n",
"client = Client(transport=transport, fetch_schema_from_transport=False)\n",
"# client = Client(transport=transport, fetch_schema_from_transport=True)\n",
"\n",
"query = gql(\n",
" '''\n",
" query pageList {\n",
" pages {\n",
" list(locale: \"en\") {\n",
" id\n",
" path\n",
" locale\n",
" title\n",
" description\n",
" contentType\n",
" isPublished\n",
" isPrivate\n",
" privateNS\n",
" createdAt\n",
" updatedAt\n",
" tags\n",
" }\n",
" }\n",
" }\n",
"'''\n",
")\n",
"\n",
"\n",
"\n",
"# result = await session.execute(query)\n",
"# print(result)\n",
"result = await client.execute_async(query)\n",
"print(result)\n",
"\n",
" \n",
"# asyncio.run(main())\n",
"# Execute the query on the transport\n",
"# result = await client.execute_async(query)\n",
"# print(result)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cfe2738f-7b10-45e2-bb31-38e8820b1ed6",
"metadata": {},
"outputs": [],
"source": [
"from gql import gql, Client\n",
"from gql.transport.aiohttp import AIOHTTPTransport\n",
"\n",
"# Select your transport with a defined url endpoint\n",
"transport = AIOHTTPTransport(url=\"https://countries.trevorblades.com/\")\n",
"\n",
"# Create a GraphQL client using the defined transport\n",
"client = Client(transport=transport, fetch_schema_from_transport=True)\n",
"\n",
"# Provide a GraphQL query\n",
"query = gql(\n",
" \"\"\"\n",
" query getContinents {\n",
" continents {\n",
" code\n",
" name\n",
" }\n",
" }\n",
"\"\"\"\n",
")\n",
"\n",
"# Execute the query on the transport\n",
"result = client.execute(query)\n",
"print(result)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.9 64-bit",
"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.8.9"
},
"toc-autonumbering": false,
"toc-showcode": false,
"toc-showtags": false,
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,198 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "5a2a0654",
"metadata": {},
"source": [
"curl --request GET \\\n",
" --url https://demo.linkace.org/api/v1/links \\\n",
" --header 'Authorization: Bearer undefined' \\\n",
" --header 'Content-Type: application/json' \\\n",
" --header 'accept: application/json'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60990b52",
"metadata": {},
"outputs": [],
"source": [
"\n"
]
},
{
"cell_type": "markdown",
"id": "ebef409e-ddc1-4cc4-bd4d-a4839ba62d66",
"metadata": {},
"source": [
"## Pull links from Linkace"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "02d6d963-538a-47c1-957f-06c7ea7c7497",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import os\n",
"import pprint\n",
"import urllib.parse\n",
"import sys\n",
"import requests\n",
"\n",
"my_headers = {\n",
" \"Authorization\": os.env(LINKACE_TOKEN),\n",
" \"Content-Type\": \"application/json\",\n",
" \"Accept\": \"application/json\",\n",
"}\n",
"\n",
"response = requests.get(\n",
" \"http://linkace/api/v1/links\",\n",
" headers=my_headers,\n",
")\n",
"\n",
"initial = response.json()\n",
"\n",
"last = initial['last_page']\n",
"\n",
"links = []\n",
"\n",
"for x in range(1, last + 1):\n",
" response = requests.get(\n",
" \"http://linkace/api/v1/links?page=\" + str(x),\n",
" headers=my_headers,\n",
" )\n",
" result = response.json()\n",
" data = result['data']\n",
" links = links + data\n",
" \n",
"out_file = open(\"links.json\", \"w\")\n",
"json.dump(links, out_file, indent = 2)\n",
"out_file.close()"
]
},
{
"cell_type": "markdown",
"id": "e6a27401-cc7d-4ffe-834d-2f051dce7025",
"metadata": {},
"source": [
"## Update Links in Directus"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f2b300a9-f7c0-4863-9696-29e92e6cedc8",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"ename": "JSONDecodeError",
"evalue": "[Errno Expecting value] : 0",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mJSONDecodeError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/requests/models.py:910\u001b[0m, in \u001b[0;36mResponse.json\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 909\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 910\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcomplexjson\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mloads\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtext\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 911\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m JSONDecodeError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 912\u001b[0m \u001b[38;5;66;03m# Catch JSON-related errors and raise as requests.JSONDecodeError\u001b[39;00m\n\u001b[1;32m 913\u001b[0m \u001b[38;5;66;03m# This aliases json.JSONDecodeError and simplejson.JSONDecodeError\u001b[39;00m\n",
"File \u001b[0;32m/opt/conda/lib/python3.9/json/__init__.py:346\u001b[0m, in \u001b[0;36mloads\u001b[0;34m(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[1;32m 343\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mcls\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m object_hook \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m 344\u001b[0m parse_int \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m parse_float \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m 345\u001b[0m parse_constant \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m object_pairs_hook \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m kw):\n\u001b[0;32m--> 346\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_default_decoder\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdecode\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 347\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mcls\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
"File \u001b[0;32m/opt/conda/lib/python3.9/json/decoder.py:337\u001b[0m, in \u001b[0;36mJSONDecoder.decode\u001b[0;34m(self, s, _w)\u001b[0m\n\u001b[1;32m 333\u001b[0m \u001b[38;5;124;03m\"\"\"Return the Python representation of ``s`` (a ``str`` instance\u001b[39;00m\n\u001b[1;32m 334\u001b[0m \u001b[38;5;124;03mcontaining a JSON document).\u001b[39;00m\n\u001b[1;32m 335\u001b[0m \n\u001b[1;32m 336\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m--> 337\u001b[0m obj, end \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraw_decode\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43midx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_w\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mend\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 338\u001b[0m end \u001b[38;5;241m=\u001b[39m _w(s, end)\u001b[38;5;241m.\u001b[39mend()\n",
"File \u001b[0;32m/opt/conda/lib/python3.9/json/decoder.py:355\u001b[0m, in \u001b[0;36mJSONDecoder.raw_decode\u001b[0;34m(self, s, idx)\u001b[0m\n\u001b[1;32m 354\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[0;32m--> 355\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m JSONDecodeError(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mExpecting value\u001b[39m\u001b[38;5;124m\"\u001b[39m, s, err\u001b[38;5;241m.\u001b[39mvalue) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[1;32m 356\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m obj, end\n",
"\u001b[0;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mJSONDecodeError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [7]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 8\u001b[0m headers \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 9\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAuthorization\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mos.env(directus_token)\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 10\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mContent-Type\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplication/json\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 11\u001b[0m }\n\u001b[1;32m 12\u001b[0m response \u001b[38;5;241m=\u001b[39m requests\u001b[38;5;241m.\u001b[39mpatch(\n\u001b[1;32m 13\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttp://directus:8055/items/bookmarks/\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m+\u001b[39m \u001b[38;5;28mstr\u001b[39m(myid),\n\u001b[1;32m 14\u001b[0m headers\u001b[38;5;241m=\u001b[39mheaders,\n\u001b[1;32m 15\u001b[0m json\u001b[38;5;241m=\u001b[39m(link),\n\u001b[1;32m 16\u001b[0m )\n\u001b[0;32m---> 17\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mresponse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjson\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m)\n",
"File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/requests/models.py:917\u001b[0m, in \u001b[0;36mResponse.json\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 915\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m RequestsJSONDecodeError(e\u001b[38;5;241m.\u001b[39mmessage)\n\u001b[1;32m 916\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 917\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m RequestsJSONDecodeError(e\u001b[38;5;241m.\u001b[39mmsg, e\u001b[38;5;241m.\u001b[39mdoc, e\u001b[38;5;241m.\u001b[39mpos)\n",
"\u001b[0;31mJSONDecodeError\u001b[0m: [Errno Expecting value] : 0"
]
}
],
"source": [
"for link in links:\n",
" url = link['url']\n",
" myid = link.pop(\"id\")\n",
" parsed_url = urllib.parse.urlparse(url)\n",
" domain = parsed_url.netloc\n",
" pdom = domain.replace(\"www.\", \"\")\n",
" link['domain'] = pdom\n",
" headers = {\n",
" \"Authorization\": \"os.env(directus_token)\",\n",
" \"Content-Type\": \"application/json\",\n",
" }\n",
" response = requests.patch(\n",
" \"http://directus:8055/items/bookmarks/\" + str(myid),\n",
" headers=headers,\n",
" json=(link),\n",
" )\n",
" print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b9d5bb9f-be1e-4db2-b0a3-d0d179e6b6a6",
"metadata": {},
"outputs": [],
"source": [
"import urllib.parse\n",
"import sys\n",
"\n",
"link = links[1]\n",
"url = link['url']\n",
"myid = link.pop(\"id\")\n",
"print(link)\n",
"parsed_url = urllib.parse.urlparse(url)\n",
"domain = parsed_url.netloc\n",
"pdom = domain.replace(\"www.\", \"\")\n",
"print(pdom)\n",
"link['domain'] = pdom\n",
"\n",
"\n",
"print(link)\n",
"\n",
"print(myid)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.9 64-bit",
"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.8.9"
},
"toc-autonumbering": false,
"toc-showcode": false,
"toc-showtags": false,
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,124 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ebef409e-ddc1-4cc4-bd4d-a4839ba62d66",
"metadata": {},
"source": [
"## Retrieve list of active proxy endpoints\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "02d6d963-538a-47c1-957f-06c7ea7c7497",
"metadata": {},
"outputs": [
{
"ename": "ConnectionError",
"evalue": "HTTPConnectionPool(host='traefik', port=8080): Max retries exceeded with url: /api/http/routers (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x117eb6760>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mgaierror\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py:174\u001b[0m, in \u001b[0;36mHTTPConnection._new_conn\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 173\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 174\u001b[0m conn \u001b[39m=\u001b[39m connection\u001b[39m.\u001b[39;49mcreate_connection(\n\u001b[1;32m 175\u001b[0m (\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_dns_host, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mport), \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtimeout, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mextra_kw\n\u001b[1;32m 176\u001b[0m )\n\u001b[1;32m 178\u001b[0m \u001b[39mexcept\u001b[39;00m SocketTimeout:\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/util/connection.py:72\u001b[0m, in \u001b[0;36mcreate_connection\u001b[0;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[39mreturn\u001b[39;00m six\u001b[39m.\u001b[39mraise_from(\n\u001b[1;32m 69\u001b[0m LocationParseError(\u001b[39mu\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m'\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m, label empty or too long\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m%\u001b[39m host), \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 70\u001b[0m )\n\u001b[0;32m---> 72\u001b[0m \u001b[39mfor\u001b[39;00m res \u001b[39min\u001b[39;00m socket\u001b[39m.\u001b[39;49mgetaddrinfo(host, port, family, socket\u001b[39m.\u001b[39;49mSOCK_STREAM):\n\u001b[1;32m 73\u001b[0m af, socktype, proto, canonname, sa \u001b[39m=\u001b[39m res\n",
"File \u001b[0;32m/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/socket.py:918\u001b[0m, in \u001b[0;36mgetaddrinfo\u001b[0;34m(host, port, family, type, proto, flags)\u001b[0m\n\u001b[1;32m 917\u001b[0m addrlist \u001b[39m=\u001b[39m []\n\u001b[0;32m--> 918\u001b[0m \u001b[39mfor\u001b[39;00m res \u001b[39min\u001b[39;00m _socket\u001b[39m.\u001b[39;49mgetaddrinfo(host, port, family, \u001b[39mtype\u001b[39;49m, proto, flags):\n\u001b[1;32m 919\u001b[0m af, socktype, proto, canonname, sa \u001b[39m=\u001b[39m res\n",
"\u001b[0;31mgaierror\u001b[0m: [Errno 8] nodename nor servname provided, or not known",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mNewConnectionError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py:703\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[0;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[1;32m 702\u001b[0m \u001b[39m# Make the request on the httplib connection object.\u001b[39;00m\n\u001b[0;32m--> 703\u001b[0m httplib_response \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_make_request(\n\u001b[1;32m 704\u001b[0m conn,\n\u001b[1;32m 705\u001b[0m method,\n\u001b[1;32m 706\u001b[0m url,\n\u001b[1;32m 707\u001b[0m timeout\u001b[39m=\u001b[39;49mtimeout_obj,\n\u001b[1;32m 708\u001b[0m body\u001b[39m=\u001b[39;49mbody,\n\u001b[1;32m 709\u001b[0m headers\u001b[39m=\u001b[39;49mheaders,\n\u001b[1;32m 710\u001b[0m chunked\u001b[39m=\u001b[39;49mchunked,\n\u001b[1;32m 711\u001b[0m )\n\u001b[1;32m 713\u001b[0m \u001b[39m# If we're going to release the connection in ``finally:``, then\u001b[39;00m\n\u001b[1;32m 714\u001b[0m \u001b[39m# the response doesn't need to know about the connection. Otherwise\u001b[39;00m\n\u001b[1;32m 715\u001b[0m \u001b[39m# it will also try to release it and we'll have a double-release\u001b[39;00m\n\u001b[1;32m 716\u001b[0m \u001b[39m# mess.\u001b[39;00m\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py:398\u001b[0m, in \u001b[0;36mHTTPConnectionPool._make_request\u001b[0;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[1;32m 397\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 398\u001b[0m conn\u001b[39m.\u001b[39;49mrequest(method, url, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mhttplib_request_kw)\n\u001b[1;32m 400\u001b[0m \u001b[39m# We are swallowing BrokenPipeError (errno.EPIPE) since the server is\u001b[39;00m\n\u001b[1;32m 401\u001b[0m \u001b[39m# legitimately able to close the connection after sending a valid response.\u001b[39;00m\n\u001b[1;32m 402\u001b[0m \u001b[39m# With this behaviour, the received response is still readable.\u001b[39;00m\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py:239\u001b[0m, in \u001b[0;36mHTTPConnection.request\u001b[0;34m(self, method, url, body, headers)\u001b[0m\n\u001b[1;32m 238\u001b[0m headers[\u001b[39m\"\u001b[39m\u001b[39mUser-Agent\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m _get_default_user_agent()\n\u001b[0;32m--> 239\u001b[0m \u001b[39msuper\u001b[39;49m(HTTPConnection, \u001b[39mself\u001b[39;49m)\u001b[39m.\u001b[39;49mrequest(method, url, body\u001b[39m=\u001b[39;49mbody, headers\u001b[39m=\u001b[39;49mheaders)\n",
"File \u001b[0;32m/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:1252\u001b[0m, in \u001b[0;36mHTTPConnection.request\u001b[0;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[1;32m 1251\u001b[0m \u001b[39m\"\"\"Send a complete request to the server.\"\"\"\u001b[39;00m\n\u001b[0;32m-> 1252\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_send_request(method, url, body, headers, encode_chunked)\n",
"File \u001b[0;32m/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:1298\u001b[0m, in \u001b[0;36mHTTPConnection._send_request\u001b[0;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[1;32m 1297\u001b[0m body \u001b[39m=\u001b[39m _encode(body, \u001b[39m'\u001b[39m\u001b[39mbody\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[0;32m-> 1298\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mendheaders(body, encode_chunked\u001b[39m=\u001b[39;49mencode_chunked)\n",
"File \u001b[0;32m/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:1247\u001b[0m, in \u001b[0;36mHTTPConnection.endheaders\u001b[0;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[1;32m 1246\u001b[0m \u001b[39mraise\u001b[39;00m CannotSendHeader()\n\u001b[0;32m-> 1247\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_send_output(message_body, encode_chunked\u001b[39m=\u001b[39;49mencode_chunked)\n",
"File \u001b[0;32m/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:1007\u001b[0m, in \u001b[0;36mHTTPConnection._send_output\u001b[0;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[1;32m 1006\u001b[0m \u001b[39mdel\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_buffer[:]\n\u001b[0;32m-> 1007\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msend(msg)\n\u001b[1;32m 1009\u001b[0m \u001b[39mif\u001b[39;00m message_body \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 1010\u001b[0m \n\u001b[1;32m 1011\u001b[0m \u001b[39m# create a consistent interface to message_body\u001b[39;00m\n",
"File \u001b[0;32m/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:947\u001b[0m, in \u001b[0;36mHTTPConnection.send\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 946\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mauto_open:\n\u001b[0;32m--> 947\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mconnect()\n\u001b[1;32m 948\u001b[0m \u001b[39melse\u001b[39;00m:\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py:205\u001b[0m, in \u001b[0;36mHTTPConnection.connect\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 204\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mconnect\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[0;32m--> 205\u001b[0m conn \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_new_conn()\n\u001b[1;32m 206\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_prepare_conn(conn)\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py:186\u001b[0m, in \u001b[0;36mHTTPConnection._new_conn\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[39mexcept\u001b[39;00m SocketError \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m--> 186\u001b[0m \u001b[39mraise\u001b[39;00m NewConnectionError(\n\u001b[1;32m 187\u001b[0m \u001b[39mself\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mFailed to establish a new connection: \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m\"\u001b[39m \u001b[39m%\u001b[39m e\n\u001b[1;32m 188\u001b[0m )\n\u001b[1;32m 190\u001b[0m \u001b[39mreturn\u001b[39;00m conn\n",
"\u001b[0;31mNewConnectionError\u001b[0m: <urllib3.connection.HTTPConnection object at 0x117eb6760>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mMaxRetryError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/requests/adapters.py:489\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[0;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[1;32m 488\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m chunked:\n\u001b[0;32m--> 489\u001b[0m resp \u001b[39m=\u001b[39m conn\u001b[39m.\u001b[39;49murlopen(\n\u001b[1;32m 490\u001b[0m method\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mmethod,\n\u001b[1;32m 491\u001b[0m url\u001b[39m=\u001b[39;49murl,\n\u001b[1;32m 492\u001b[0m body\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mbody,\n\u001b[1;32m 493\u001b[0m headers\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mheaders,\n\u001b[1;32m 494\u001b[0m redirect\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m 495\u001b[0m assert_same_host\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m 496\u001b[0m preload_content\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m 497\u001b[0m decode_content\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m 498\u001b[0m retries\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmax_retries,\n\u001b[1;32m 499\u001b[0m timeout\u001b[39m=\u001b[39;49mtimeout,\n\u001b[1;32m 500\u001b[0m )\n\u001b[1;32m 502\u001b[0m \u001b[39m# Send the request.\u001b[39;00m\n\u001b[1;32m 503\u001b[0m \u001b[39melse\u001b[39;00m:\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py:787\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[0;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[1;32m 785\u001b[0m e \u001b[39m=\u001b[39m ProtocolError(\u001b[39m\"\u001b[39m\u001b[39mConnection aborted.\u001b[39m\u001b[39m\"\u001b[39m, e)\n\u001b[0;32m--> 787\u001b[0m retries \u001b[39m=\u001b[39m retries\u001b[39m.\u001b[39;49mincrement(\n\u001b[1;32m 788\u001b[0m method, url, error\u001b[39m=\u001b[39;49me, _pool\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m, _stacktrace\u001b[39m=\u001b[39;49msys\u001b[39m.\u001b[39;49mexc_info()[\u001b[39m2\u001b[39;49m]\n\u001b[1;32m 789\u001b[0m )\n\u001b[1;32m 790\u001b[0m retries\u001b[39m.\u001b[39msleep()\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/urllib3/util/retry.py:592\u001b[0m, in \u001b[0;36mRetry.increment\u001b[0;34m(self, method, url, response, error, _pool, _stacktrace)\u001b[0m\n\u001b[1;32m 591\u001b[0m \u001b[39mif\u001b[39;00m new_retry\u001b[39m.\u001b[39mis_exhausted():\n\u001b[0;32m--> 592\u001b[0m \u001b[39mraise\u001b[39;00m MaxRetryError(_pool, url, error \u001b[39mor\u001b[39;00m ResponseError(cause))\n\u001b[1;32m 594\u001b[0m log\u001b[39m.\u001b[39mdebug(\u001b[39m\"\u001b[39m\u001b[39mIncremented Retry for (url=\u001b[39m\u001b[39m'\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m): \u001b[39m\u001b[39m%r\u001b[39;00m\u001b[39m\"\u001b[39m, url, new_retry)\n",
"\u001b[0;31mMaxRetryError\u001b[0m: HTTPConnectionPool(host='traefik', port=8080): Max retries exceeded with url: /api/http/routers (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x117eb6760>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mConnectionError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add traefic routers.ipynb Cell 2\u001b[0m in \u001b[0;36m<cell line: 10>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=2'>3</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mrequests\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=4'>5</a>\u001b[0m my_headers \u001b[39m=\u001b[39m {\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=5'>6</a>\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mContent-Type\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mapplication/json\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=6'>7</a>\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mAccept\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mapplication/json\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=7'>8</a>\u001b[0m }\n\u001b[0;32m---> <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=9'>10</a>\u001b[0m response \u001b[39m=\u001b[39m requests\u001b[39m.\u001b[39;49mget(\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=10'>11</a>\u001b[0m \u001b[39m\"\u001b[39;49m\u001b[39mhttp://traefik:8080/api/http/routers\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=11'>12</a>\u001b[0m headers\u001b[39m=\u001b[39;49mmy_headers,\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=12'>13</a>\u001b[0m )\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=15'>16</a>\u001b[0m initial \u001b[39m=\u001b[39m response\u001b[39m.\u001b[39mjson()\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=18'>19</a>\u001b[0m \u001b[39mfor\u001b[39;00m x \u001b[39min\u001b[39;00m initial:\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/requests/api.py:73\u001b[0m, in \u001b[0;36mget\u001b[0;34m(url, params, **kwargs)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mget\u001b[39m(url, params\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 63\u001b[0m \u001b[39mr\u001b[39m\u001b[39m\"\"\"Sends a GET request.\u001b[39;00m\n\u001b[1;32m 64\u001b[0m \n\u001b[1;32m 65\u001b[0m \u001b[39m :param url: URL for the new :class:`Request` object.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 70\u001b[0m \u001b[39m :rtype: requests.Response\u001b[39;00m\n\u001b[1;32m 71\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 73\u001b[0m \u001b[39mreturn\u001b[39;00m request(\u001b[39m\"\u001b[39;49m\u001b[39mget\u001b[39;49m\u001b[39m\"\u001b[39;49m, url, params\u001b[39m=\u001b[39;49mparams, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/requests/api.py:59\u001b[0m, in \u001b[0;36mrequest\u001b[0;34m(method, url, **kwargs)\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[39m# By using the 'with' statement we are sure the session is closed, thus we\u001b[39;00m\n\u001b[1;32m 56\u001b[0m \u001b[39m# avoid leaving sockets open which can trigger a ResourceWarning in some\u001b[39;00m\n\u001b[1;32m 57\u001b[0m \u001b[39m# cases, and look like a memory leak in others.\u001b[39;00m\n\u001b[1;32m 58\u001b[0m \u001b[39mwith\u001b[39;00m sessions\u001b[39m.\u001b[39mSession() \u001b[39mas\u001b[39;00m session:\n\u001b[0;32m---> 59\u001b[0m \u001b[39mreturn\u001b[39;00m session\u001b[39m.\u001b[39;49mrequest(method\u001b[39m=\u001b[39;49mmethod, url\u001b[39m=\u001b[39;49murl, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/requests/sessions.py:587\u001b[0m, in \u001b[0;36mSession.request\u001b[0;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[1;32m 582\u001b[0m send_kwargs \u001b[39m=\u001b[39m {\n\u001b[1;32m 583\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mtimeout\u001b[39m\u001b[39m\"\u001b[39m: timeout,\n\u001b[1;32m 584\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mallow_redirects\u001b[39m\u001b[39m\"\u001b[39m: allow_redirects,\n\u001b[1;32m 585\u001b[0m }\n\u001b[1;32m 586\u001b[0m send_kwargs\u001b[39m.\u001b[39mupdate(settings)\n\u001b[0;32m--> 587\u001b[0m resp \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msend(prep, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49msend_kwargs)\n\u001b[1;32m 589\u001b[0m \u001b[39mreturn\u001b[39;00m resp\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/requests/sessions.py:701\u001b[0m, in \u001b[0;36mSession.send\u001b[0;34m(self, request, **kwargs)\u001b[0m\n\u001b[1;32m 698\u001b[0m start \u001b[39m=\u001b[39m preferred_clock()\n\u001b[1;32m 700\u001b[0m \u001b[39m# Send the request\u001b[39;00m\n\u001b[0;32m--> 701\u001b[0m r \u001b[39m=\u001b[39m adapter\u001b[39m.\u001b[39;49msend(request, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 703\u001b[0m \u001b[39m# Total elapsed time of the request (approximately)\u001b[39;00m\n\u001b[1;32m 704\u001b[0m elapsed \u001b[39m=\u001b[39m preferred_clock() \u001b[39m-\u001b[39m start\n",
"File \u001b[0;32m~/Library/Python/3.8/lib/python/site-packages/requests/adapters.py:565\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[0;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[1;32m 561\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, _SSLError):\n\u001b[1;32m 562\u001b[0m \u001b[39m# This branch is for urllib3 v1.22 and later.\u001b[39;00m\n\u001b[1;32m 563\u001b[0m \u001b[39mraise\u001b[39;00m SSLError(e, request\u001b[39m=\u001b[39mrequest)\n\u001b[0;32m--> 565\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mConnectionError\u001b[39;00m(e, request\u001b[39m=\u001b[39mrequest)\n\u001b[1;32m 567\u001b[0m \u001b[39mexcept\u001b[39;00m ClosedPoolError \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 568\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mConnectionError\u001b[39;00m(e, request\u001b[39m=\u001b[39mrequest)\n",
"\u001b[0;31mConnectionError\u001b[0m: HTTPConnectionPool(host='traefik', port=8080): Max retries exceeded with url: /api/http/routers (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x117eb6760>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))"
]
}
],
"source": [
"import json\n",
"import re\n",
"import requests\n",
"\n",
"my_headers = {\n",
" \"Content-Type\": \"application/json\",\n",
" \"Accept\": \"application/json\",\n",
"}\n",
"\n",
"response = requests.get(\n",
" \"http://traefik:8080/api/http/routers\",\n",
" headers=my_headers,\n",
")\n",
"\n",
"\n",
"initial = response.json()\n",
"\n",
"\n",
"for x in initial:\n",
" service = x[\"rule\"]\n",
" find = re.findall(\"Host\\(`([^\\)]+)`\\)\", service)\n",
" try:\n",
" print(find[0])\n",
" except:\n",
" pass"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.4 64-bit",
"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.8.9"
},
"toc-autonumbering": false,
"toc-showcode": false,
"toc-showtags": false,
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "927fe89f-9660-4681-884b-f258fc669b88",
"metadata": {},
"outputs": [],
"source": [
"pip install gql[all] aiohttp"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4dc5471-3df9-4d52-865e-ca9202d472a3",
"metadata": {},
"outputs": [],
"source": [
"import asyncio\n",
"\n",
"from gql import Client, gql\n",
"from gql.transport.aiohttp import AIOHTTPTransport\n",
"\n",
"transport = AIOHTTPTransport(\n",
" url=\"http://directus:8055/graphql\",\n",
" headers={\n",
" \"Content-type\": \"application/json\",\n",
" \"Authorization\": \"os.env(directus_token)\",\n",
" },\n",
")\n",
"\n",
"client = Client(transport=transport, fetch_schema_from_transport=False)\n",
"\n",
"query = gql(\n",
" \"\"\"\n",
" query {\n",
" pages {\n",
" id\n",
" }\n",
" }\n",
"\"\"\"\n",
")\n",
"\n",
"result = await client.execute_async(query)\n",
"print(result)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9429bdb-d291-49ce-8191-9977b3624f97",
"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"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,128 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "c5130422",
"metadata": {},
"source": [
"# Bulk upload data via GraphQL endpoint"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "0019cd52-56b8-4f1d-82f5-55137f05456b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"zsh:1: no matches found: gql[all]\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"pip install gql[all] aiohttp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6658fd82-d8db-4a80-a103-3f015c851e69",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'gql'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js query.ipynb Cell 3\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=0'>1</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39masyncio\u001b[39;00m\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=2'>3</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mgql\u001b[39;00m \u001b[39mimport\u001b[39;00m Client, gql\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=3'>4</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mgql\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mtransport\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39maiohttp\u001b[39;00m \u001b[39mimport\u001b[39;00m AIOHTTPTransport\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=5'>6</a>\u001b[0m transport \u001b[39m=\u001b[39m AIOHTTPTransport(\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=6'>7</a>\u001b[0m url\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mhttp://wiki:3000/graphql\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=7'>8</a>\u001b[0m headers\u001b[39m=\u001b[39m{\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=10'>11</a>\u001b[0m },\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=11'>12</a>\u001b[0m )\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'gql'"
]
}
],
"source": [
"import asyncio\n",
"\n",
"from gql import Client, gql\n",
"from gql.transport.aiohttp import AIOHTTPTransport\n",
"\n",
"transport = AIOHTTPTransport(\n",
" url=\"http://wiki:3000/graphql\",\n",
" headers={\n",
" \"Content-type\": \"application/json\",\n",
" \"Authorization\": \"os.env(directus_token)\",\n",
" },\n",
")\n",
"\n",
"client = Client(transport=transport, fetch_schema_from_transport=False)\n",
"\n",
"query = gql(\n",
" \"\"\"\n",
" query pageList {\n",
" pages {\n",
" list(locale: \"en\") {\n",
" id\n",
" path\n",
" locale\n",
" title\n",
" description\n",
" contentType\n",
" isPublished\n",
" isPrivate\n",
" privateNS\n",
" createdAt\n",
" updatedAt\n",
" tags\n",
" }\n",
" }\n",
" }\n",
"\"\"\"\n",
")\n",
"\n",
"result = await client.execute_async(query)\n",
"print(result)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.9 64-bit",
"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.8.9"
},
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Webpage</title>
</head>
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}
</ul>
[{{ name }}]
prefix = https://
url = your-website.com
icon = static/images/apps/sh.png
sidebar_icon = static/images/apps/{{ name }}.png
description = default
open_in = iframe
data_sources = sh_http,sh_health,sh_ping,sh_rest
tags = default
groups = admin_only
{# a comment #}
</body>
</html>
[{{ name }}]
prefix = https://
url = your-website.com
icon = static/images/apps/sh.png
sidebar_icon = static/images/apps/{{ name }}.png
description = default
open_in = iframe
data_sources = sh_http,sh_health,sh_ping,sh_rest
tags = default
groups = admin_only
{# a comment #}
</body>
</html>

@ -0,0 +1,114 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "db42eb08",
"metadata": {},
"source": [
"# Robot Framework\n",
"\n",
"[docs](https://robocorp.com/docs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2f5ca23-5eed-4eb6-9c1b-2152b08009a5",
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mFailed to start the Kernel. \n",
"Kernel Python 3.9.13 64-bit is not usable. Check the Jupyter output tab for more information. \n",
"View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
]
}
],
"source": [
"*** Settings ***\n",
"Documentation Simple example using SeleniumLibrary.\n",
"Library SeleniumLibrary\n",
"\n",
"*** Variables ***\n",
"${LOGIN URL} http://localhost:7272\n",
"${BROWSER} Chrome\n",
"\n",
"*** Test Cases ***\n",
"Valid Login\n",
" Open Browser To Login Page\n",
" Input Username demo\n",
" Input Password mode\n",
" Submit Credentials\n",
" Welcome Page Should Be Open\n",
" [Teardown] Close Browser\n",
"\n",
"*** Keywords ***\n",
"Open Browser To Login Page\n",
" Open Browser ${LOGIN URL} ${BROWSER}\n",
" Title Should Be Login Page\n",
"\n",
"Input Username\n",
" [Arguments] ${username}\n",
" Input Text username_field ${username}\n",
"\n",
"Input Password\n",
" [Arguments] ${password}\n",
" Input Text password_field ${password}\n",
"\n",
"Submit Credentials\n",
" Click Button login_button\n",
"\n",
"Welcome Page Should Be Open\n",
" Title Should Be Welcome Page"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78a7b507-e8f5-4dab-9d38-fb5396e92b42",
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mFailed to start the Kernel. \n",
"Kernel Python 3.9.13 64-bit is not usable. Check the Jupyter output tab for more information. \n",
"View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
]
}
],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.13 64-bit",
"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.13"
},
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading…
Cancel
Save