You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
324 lines
8.1 KiB
324 lines
8.1 KiB
{ |
|
"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": "73420231-210c-46b0-8c5f-be26ce0f409f", |
|
"metadata": {}, |
|
"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", |
|
"\n", |
|
"items = data[\"data\"]" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "513b90bb-b873-4fa2-8e26-197af7fea6ce", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"%%sh\n", |
|
"rm templates/wiki-js.md\n", |
|
"\n", |
|
"cat << EOF >> templates/wiki-js.md\n", |
|
"\n", |
|
"# {{ item.id }}\n", |
|
"\n", |
|
"hello\n" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "3ee85b3d-19bc-47c9-9af6-2d08f7bf577b", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"from jinja2 import Environment, FileSystemLoader, select_autoescape\n", |
|
"env = Environment(\n", |
|
" loader = FileSystemLoader([\"templates\"]),\n", |
|
" # autoescape=select_autoescape()\n", |
|
")\n", |
|
"\n", |
|
"t = env.get_template(\"wiki-js.md\")\n", |
|
"pprint.pprint(t.render(item=items[0],items=items))\n", |
|
"# \n", |
|
"with open(\"test.ini\", \"w\") as external_file:\n", |
|
" # add_text = \"This text will be added to the file\"\n", |
|
" print(t.render(item=items[0],items=items), file=external_file)\n", |
|
" external_file.close()" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 13, |
|
"id": "dca88210-18db-45ee-9949-7010b92dbae7", |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"name": "stdout", |
|
"output_type": "stream", |
|
"text": [ |
|
"/home/jovyan/code/directus\n" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"import json\n", |
|
"import os\n", |
|
"import pprint\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": [ |
|
"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": "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": 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 (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 |
|
}
|
|
|