Skip to content

Instantly share code, notes, and snippets.

@DaRaFF
Last active March 18, 2021 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaRaFF/42f243220cdb83f81e98d308d9278d1a to your computer and use it in GitHub Desktop.
Save DaRaFF/42f243220cdb83f81e98d308d9278d1a to your computer and use it in GitHub Desktop.
#!/bin/bash
DESIGNNAME=${4:-"living-times"}
DESIGNVERSION=${5:-"1.0.2"}
echo "-------ARGUMENTS-------------"
echo "Generate documentId from: $1"
echo "Generate documentId to: $2"
echo "Title postfix: $3"
echo "Design name $DESIGNNAME"
echo "Desig version $DESIGNVERSION"
echo "-----------------------------"
for ((i = $1; i <= $2; i++)); do
echo "import article with id $i"
CHECKSUM=$((1 + RANDOM % 1000000))
curl -k -X POST "https://0.0.0.0:9000/proxy/api/api/v1/import/documents" \
-H "Accept: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json; charset=utf-8' \
--data-binary @- << EOF
{
"systemName": "identifier-for-your-system",
"webhook": "https://webhook.site/c87057b1-0224-42bb-984c-5eab3ad3744d",
"documents": [ {
"id": "$i",
"title": "this is document $i $3",
"contentType": "regular",
"checksum": "$i$CHECKSUM",
"livingdoc": {
"content": [
{
"identifier": "living-times.article-container",
"id": "doc-1e9db5b440",
"position": "fixed",
"containers": {
"header": [
{
"identifier": "living-times.head",
"id": "doc-1e9db5b450",
"content": {
"title": "this is document $i $3",
"text": "this is a automatically generated article via public api import",
"author": "Sub Zero",
"date": "01.01.2000"
}
}
],
"main": [
{
"identifier": "living-times.image",
"id": "doc-1e9db5b460"
},
{
"identifier": "living-times.paragraph",
"id": "doc-1e9db5b470"
},
{
"identifier": "living-times.teaser-author",
"id": "doc-1e9db5b471",
"content": {
"embed": {
"service": "teaser",
"params": {
"layout": "author-embed"
}
}
}
}
]
}
}
],
"design": {
"name": "$DESIGNNAME",
"version": "$DESIGNVERSION"
}
},
"metadata": {
"description": "foo"
},
"flags": {
"autoPublish": true
}
}]
}
EOF
done
@DaRaFF
Copy link
Author

DaRaFF commented Jun 12, 2020

Example how to import some fake document into Livingdocs

  • attention, you have to change maybe some configs
    • server config - increase import.jobs.imageDailyLimit // 100000
    • server config - increase import.jobs.documentDailyLimit // 100000
    • server config - increase db.max // 20
export ACCESS_TOKEN=<your-livingdocs-public-api-access-token>

# this example imports 50 articles on your localhost with the title "100 hello", "101 hello", ... "150 hello"  with a design 'living-times@1.0.2'
# Attention! Currently it's only working with the magazine project which haves a living-times design
curl 
https://gist.githubusercontent.com/DaRaFF/42f243220cdb83f81e98d308d9278d1a/raw/9f2d2ea20c69bd0bb2c08eec616246ed7e41ea65/import-documents-to-livingdocs.sh | bash -s 100 150 "hello" "living-times" "1.0.2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment