{ "cells": [ { "cell_type": "code", "execution_count": 138, "id": "dca88210-18db-45ee-9949-7010b92dbae7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/jovyan\n" ] } ], "source": [ "import json\n", "\n", "# from json import JSONEncoder\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": 139, "id": "7374f89e-23f8-407d-967b-c76e7d6d93a2", "metadata": { "tags": [] }, "outputs": [], "source": [ "with open(\"scrubbed_records.json\") as f:\n", " scrubbed_records = json.load(f)\n", "# with open(\"keys.json\") as key1:\n", "# keys = json.load(key1);\n", "\n", "# print(scrubbed_records[0])\n", "\n", "# d8 = keys | scrubbed_records\n", "# print(d8)\n", "# merged = {key: value for (key, value) in (keys.items() + scrubbed_records.items())}\n", "# jsonString_merged =" ] }, { "cell_type": "code", "execution_count": null, "id": "f0367eee-e052-4184-b016-8ecb0dd1aa32", "metadata": { "tags": [] }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 140, "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": {}, "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_job_posts_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", "# title = 'article_attributes_data-posted-on'\n", "# \"article_attributes_data-posted-on\": \"Capital One\",\n", "# \"article_attributes_data-listing-version-key\": \"DwJbw6IxmCHCl9sUWenVkQ.--M7HviTGj7\",\n", "# \"article_attributes_data-job-id\": \"tmp_dc_capitalone_tier2_perengo_cpc9e35f5e59e35f5e5-lzqj0cb\",\n", "# \"article_attributes_data-location\": \"Royse City, TX\",\n", "# \"article_attributes_data-lat\": 32.9751205444,\n", "# \"article_attributes_data-lng\": -96.3324813843,\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": 136, "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_json_server_item(\n", "# id: \"ziprecruiter\"\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": [] } ], "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 }