This bash script helps downloading a whole subreddit wiki. Thanks to u/ThePixelHunter (https://www.reddit.com/user/ThePixelHunter/) for the original script adapted to work on Windows machine with added line 10.
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 -x | |
# Requires: bash coreutils curl jq | |
USER_AGENT='superagent/1.0' | |
EXPORTDIR="exports" | |
while read -r line; do | |
SUBREDDIT="$line" | |
SUBREDDIT=`echo $SUBREDDIT | sed 's/\\r//g'` | |
while read -r line; do | |
PAGE="$line" ; PAGE=$(echo $PAGE | sed 's|\/|\-\-|g') | |
mkdir -p "./$EXPORTDIR/$SUBREDDIT/wiki/$PAGE" | |
curl -s --user-agent "$USER_AGENT" "https://www.reddit.com/r/$SUBREDDIT/wiki/$PAGE.json" > "./$EXPORTDIR/$SUBREDDIT/wiki/$PAGE.json" | |
printf "$SUBREDDIT/wiki/$PAGE " ; echo $? | |
jq -r '.data.content_md' "./$EXPORTDIR/$SUBREDDIT/wiki/$PAGE.json" > "./$EXPORTDIR/$SUBREDDIT/wiki/$PAGE.md" | |
find . -type d -exec rmdir '{}' \; > /dev/null 2>&1 | |
done < <(curl -S --user-agent "$USER_AGENT" "https://www.reddit.com/r/$SUBREDDIT/wiki/pages.json" | jq -r '.data | .[]') | |
done < subreddits.list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basic idea :
Guide
Edit that I made to work on Windows with git-bash or WSL (Windows Subsystem for Linux) :