Skip to content

Instantly share code, notes, and snippets.

@kostajh
Last active December 11, 2020 11:18
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 kostajh/32c0201f4049a66031b2c61bc4ff0856 to your computer and use it in GitHub Desktop.
Save kostajh/32c0201f4049a66031b2c61bc4ff0856 to your computer and use it in GitHub Desktop.
Query addlink-simple on Toolforge
#!/bin/bash
set -e
WIKI=$1
TITLE=$2
if [ -z "$3" ]; then
THRESHOLD=0.5
else
THRESHOLD=$3
fi
URL="https://$WIKI.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&rvprop=ids%7Ccontent&rvslots=main"
RESPONSE=$(curl --data-urlencode titles="$TITLE" -s "$URL")
PAGEID=$(echo "$RESPONSE" | jq -r .query.pages[].pageid )
REVID=$(echo "$RESPONSE" | jq -r .query.pages[].revisions[].revid)
CONTENT=$(echo "$RESPONSE" | jq -r '.query.pages[].revisions[].slots.main."*"')
ENCODED_CONTENT=$(echo "$CONTENT" | jq -sR tojson)
ENDPOINT="https://addlink-simple.toolforge.org/query"
JSON="{\"max_recommendations\": 10,
\"page_title\": \"$TITLE\",
\"revid\": $REVID,
\"pageid\": $PAGEID,
\"wiki_id\": \"$WIKI\",
\"wikitext\": $ENCODED_CONTENT,
\"threshold\": 0.5}"
echo "$JSON" | curl -d @- --header "Content-Type: application/json" -s "$ENDPOINT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment