{ "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", "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": "f0367eee-e052-4184-b016-8ecb0dd1aa32", "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "for x in scrubbed_records:\n", " # pprint.pprint(x)\n", " item = scrubbed_records[0]\n", " name = item['Name']\n", " image = item['Config']['Image']\n", " image = (image.replace(':latest', ''))\n", " name = (name.replace('/', ''))\n", " data = x" ] }, { "cell_type": "code", "execution_count": null, "id": "4f03fbfe-147b-4011-b71f-b9031810aa44", "metadata": { "tags": [] }, "outputs": [], "source": [ "# print(jsonString_merged)" ] }, { "cell_type": "code", "execution_count": null, "id": "b2983b27-6169-4a16-bc70-adfe9b6023b0", "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "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", "job_posts = gql(\n", " \"\"\"\n", "mutation{\n", " update_containers_item(id: ______, data: ______){\n", " id\n", " status\n", " sort\n", " date_created\n", " date_updated\n", " json_object\n", " }\n", "}\n", "\"\"\"\n", ")\n", "\n", "\n", "y = json.dumps(scrubbed_records)\n", "for x in y:\n", "\n", " # ef = x.loads()\n", " # print(x)\n", " # id = x[\"article_attributes_data-listing-version-key\"]\n", " # pairs = y.items()\n", " pprint.pprint(x)\n", "# print(y)\n", "# id = y[\"article_attributes_data-listing-version-key\"]\n", "# print(id)\n", "# data = y[scrubbed_record]\n", "# print(scrubbed_record)\n", "\n", "\n", "# Mutation ($data: JSON!) {\n", "# update_job_blocks_item(\n", "# id: \"ziprecruiter\"\n", "# data: {\n", "# title: $title\n", "# }\n", "# )\n", "# }\n", "\n", "\n", "\n", "# print(title)\n", "\n", "# params = { \"title\": article_attributes_data-posted-on }\n", "\n", "# result = client.execute(mutate, variable_values=params)" ] }, { "cell_type": "code", "execution_count": null, "id": "28c500a2-becf-4d86-a88d-c1f30b3a5e99", "metadata": {}, "outputs": [], "source": [ "import pprint\n", "\n", "# print(result)\n", "\n", "# query = gql('''\n", "# query {\n", "# json_server_by_id(id: \"ziprecruiter\") {\n", "# data\n", "# }\n", "# }\n", "# ''')\n", "\n", "\n", "mutate = gql(\n", " \"\"\"\n", " mutation ($data: JSON!) {\n", " update_containers_item(\n", " id: \"test\"\n", " data: {\n", " data: $data\n", " }\n", " ) {\n", " data\n", " }\n", " }\n", "\"\"\"\n", ")\n", "\n", "# add = gql(\n", "# \"\"\"\n", "# mutation ($create_test_data: [create_test_input!]) {\n", "# create_test_items( data: $create_test_data ) {\n", "# id\n", "# json_object\n", "# }\n", "# }\n", "# \"\"\"\n", "# )\n", "# init = gql(\n", "# \"\"\"\n", "# mutation ($collection: String!, $data: !) {\n", "# create_fields_item(collection: \"job_posts\", data: { field: \"title\", type: \"string\" ) {\n", "# collection\n", "# field\n", "# }\n", "# }\n", "# \"\"\"\n", "# )\n", "\n", "test3 = { \"field\": \"title\", type: \"string\", \"meta\": { \"icon\": \"title\" }, \"schema\": { \"default_value\": \"null\" } }\n", "\n", "params = {\"collection\": \"job_posts\", \"data\": test3}\n", "\n", "result = client.execute(init, variable_values=params)\n", "# print(result)" ] }, { "cell_type": "code", "execution_count": null, "id": "2a52af9c-4127-4dbf-bac4-20086433fc80", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "f2b300a9-f7c0-4863-9696-29e92e6cedc8", "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "import requests\n", "\n", "input_set = {\n", " \"id\": \"tee\",\n", " \"name\": \"ffff\"\n", "}\n", "\n", "# import jsonify\n", "my_headers = {\"Authorization\": \"os.env(directus_token)\", \"Content-Type\": \"application/json\"}\n", "response = requests.post(\n", " \"https://cms.donavanaldrich.com/fields/containers\", headers=my_headers, json=(input_set)\n", ")\n", "print(response.json())\n", "# r = response.json()\n", "# print(r)\n", "# p = json.dumps(r)\n", "# print(p)\n", "# with open('blog_posts_fields.json', 'w') as output:\n", "# json.dumps(input)\n", "# # print(input_set)\n", "# with open('blog_posts_fields.json', 'w') as f:\n", "# json.dump(p, f, indent=8)" ] } ], "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 }