Skip to content

Instantly share code, notes, and snippets.

@seansummers
Forked from ssummer3/convert.json
Created March 29, 2018 17:39
Show Gist options
  • Save seansummers/4de451c918f098ba2a9ed0c75b053553 to your computer and use it in GitHub Desktop.
Save seansummers/4de451c918f098ba2a9ed0c75b053553 to your computer and use it in GitHub Desktop.
Contentful Stuffs
{
"universityarchives": "5561",
"reservesmicrotextandmediadesk": "5557",
"medievalinstitutelibrary": "5558",
"circulationservicedesk": "1483",
"engineeringlibrary": "5566",
"architecturelibrary": "5563",
"kelloggkroclibrary": "5567",
"mahaffeybusinesslibrary": "5564",
"chemistryphysicslibrary": "5565",
"centerfordigitalscholarship": "5560",
"rarebooksspecialcollections": "5556",
"omearamathematicslibrary": "5569",
"askusdesk": "5540",
"hesburghlibrary": "426",
"radiationchemistryreadingroom": "5570",
"visualresourcescenter": "5571",
"musiclibrary": "6092",
"oitoutpost": "6091"
}
#! /bin/bash
## set these
SPACE=
CONTENTFUL_KEY=
curl -s \
-H "Authorization: Bearer ${CONTENTFUL_KEY}" \
"https://api.contentful.com/spaces/${SPACE}/entries?content_type=servicePoint&select=fields,sys.id,sys.version,sys.publishedVersion&limit=200" \
| jq '
.items[]
| select(.sys.publishedVersion and .fields.hoursCode)
| { id: .sys.id,
version: .sys.version,
data: {fields: .fields},
}
' \
| jq --slurpfile convert convert.json -c '
.data.fields.hoursCode["en-US"]=$convert[0][.data.fields.hoursCode["en-US"]]
| select(.data.fields.hoursCode["en-US"])
' \
| jq -r '"\(.id) \(.version) \(.data | tojson | @sh)"' \
| while read id version data; do
curl -X PUT \
-H "Authorization: Bearer ${CONTENTFUL_KEY}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-H "X-Contentful-Version: ${version}" \
-d "${data}" \
"https://api.contentful.com/spaces/${SPACE}/entries/${id}" #\
| jq -r '"\(.sys.version)"' \
| while read newversion; do
curl -X PUT
-H "Authorization: Bearer ${CONTENTFUL_KEY}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-H "X-Contentful-Version: ${newversion}" \
"https://api.contentful.com/spaces/${SPACE}/entries/${id}/published"
done
done
---
- name: update contentful for hours
hosts: library-web-campus-1
strategy: free
tasks:
- name: update contentful
uri:
url: 'https://api.contentful.com/spaces/{{ space }}/entries?content_type=servicePoint&select=fields,sys.id,sys.version,sys.publishedVersion&limit=200'
headers:
Authorization: 'Bearer {{ contentful_key }}'
return_content: true
register: contentful
delegate_to: localhost
- set_fact:
has_hours: >
{{
(contentful.content | from_json)
| json_query("
items[?sys.publishedVersion && fields.hoursCode].{
id: sys.id,
version: sys.version,
data: { fields: fields }
}")
}}
- command: >
jq --argjson convert {{ convert | to_json | quote }} '.[]|.data.fields.hoursCode["en-US"]=$convert[.data.fields.hoursCode["en-US"]]'
args:
stdin: '{{ has_hours | to_json }}'
register: jq_out
delegate_to: localhost
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment