Last active
December 11, 2020 11:18
-
-
Save kostajh/32c0201f4049a66031b2c61bc4ff0856 to your computer and use it in GitHub Desktop.
Query addlink-simple on Toolforge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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