Published: by Vika

Tags:
  • couchdb
  • micropub
  • ownyourdata

I've just exported my Micropub posts to CouchDB using just curl and jq. Here's the command:


curl --silent -H "Authorization: Bearer $MICROPUB_ACCESS_TOKEN" "${MICROPUB_ENDPOINT}?q=source&limit=$LIMIT"  | jq '{
  "docs": .items | map(. + {
    "_id": .properties.published[] | strptime("%Y-%m-%dT%H:%M:%S%Z") | mktime | tostring
  }) | map(
    if .properties | has("visibility") then
      .
    else (
      .  * {"properties": {"visibility": ["public"]}}
    ) end
  )
}' | curl -u $COUCHDB_AUTH localhost:5984/posts/_bulk_docs -X POST -d@- -H "Content-Type: application/json"

The variables $LIMIT (count of posts to be exported), $MICROPUB_ACCESS_TOKEN, $MICROPUB_TOKEN and $COUCHDB_AUTH are set by user.