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.
7.3 KiB
7.3 KiB
<html>
<head>
</head>
</html>
In [ ]:
pip install gql
In [ ]:
import json
import os
import pprint
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
cwd = os.getcwd()
print(cwd)
In [ ]:
with open("/home/jovyan/code/directus/docker.json") as f:
scrubbed_records = json.load(f)
# print(scrubbed_records[0])
item = scrubbed_records[0]
name = item['Name']
image = item['Config']['Image']
# print(name)
# print(image)
image = (image.replace(':latest', ''))
name = (name.replace('/', ''))
print(name)
print(image)
In [ ]:
for x in scrubbed_records:
# pprint.pprint(x)
item = scrubbed_records[0]
name = item['Name']
image = item['Config']['Image']
image = (image.replace(':latest', ''))
name = (name.replace('/', ''))
data = x
In [ ]:
# print(jsonString_merged)
In [ ]:
sample_transport = RequestsHTTPTransport(
url="http://directus:8055/graphql",
use_json=True,
headers={
"Content-type": "application/json",
"Authorization": "os.env(directus_token)",
},
verify=True,
retries=3,
)
client = Client(
transport=sample_transport,
fetch_schema_from_transport=True,
)
job_posts = gql(
"""
mutation{
update_containers_item(id: ______, data: ______){
id
status
sort
date_created
date_updated
json_object
}
}
"""
)
y = json.dumps(scrubbed_records)
for x in y:
# ef = x.loads()
# print(x)
# id = x["article_attributes_data-listing-version-key"]
# pairs = y.items()
pprint.pprint(x)
# print(y)
# id = y["article_attributes_data-listing-version-key"]
# print(id)
# data = y[scrubbed_record]
# print(scrubbed_record)
# Mutation ($data: JSON!) {
# update_job_blocks_item(
# id: "ziprecruiter"
# data: {
# title: $title
# }
# )
# }
# print(title)
# params = { "title": article_attributes_data-posted-on }
# result = client.execute(mutate, variable_values=params)
In [ ]:
import pprint
# print(result)
# query = gql('''
# query {
# json_server_by_id(id: "ziprecruiter") {
# data
# }
# }
# ''')
mutate = gql(
"""
mutation ($data: JSON!) {
update_containers_item(
id: "test"
data: {
data: $data
}
) {
data
}
}
"""
)
# add = gql(
# """
# mutation ($create_test_data: [create_test_input!]) {
# create_test_items( data: $create_test_data ) {
# id
# json_object
# }
# }
# """
# )
# init = gql(
# """
# mutation ($collection: String!, $data: !) {
# create_fields_item(collection: "job_posts", data: { field: "title", type: "string" ) {
# collection
# field
# }
# }
# """
# )
test3 = { "field": "title", type: "string", "meta": { "icon": "title" }, "schema": { "default_value": "null" } }
params = {"collection": "job_posts", "data": test3}
result = client.execute(init, variable_values=params)
# print(result)
In [ ]:
In [ ]:
import json
import requests
input_set = {
"id": "tee",
"name": "ffff"
}
# import jsonify
my_headers = {"Authorization": "os.env(directus_token)", "Content-Type": "application/json"}
response = requests.post(
"https://cms.donavanaldrich.com/fields/containers", headers=my_headers, json=(input_set)
)
print(response.json())
# r = response.json()
# print(r)
# p = json.dumps(r)
# print(p)
# with open('blog_posts_fields.json', 'w') as output:
# json.dumps(input)
# # print(input_set)
# with open('blog_posts_fields.json', 'w') as f:
# json.dump(p, f, indent=8)