iama_alpaca

RedditTextScraper.sh

May 31st, 2017
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.12 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # Usage: ./RedditTextScraper.sh <subreddit (Caps sensitive!)> <time (day, week, month, year or all)> <number of posts to download>
  4. # Example: ./RedditTextScraper.sh DataHoarder month 20
  5.  
  6. # Downloads the given subreddit and take parameters for time and number of posts.
  7. wget -e robots=off -p -k -r --level=1 -I /r/$1/comments https://www.reddit.com/r/$1/top/\?sort\=top\&t\=$2\&limit\=$3
  8.  
  9. # Removes the string "data-inbound-url" from the main html file because it interferes with the ability to open comment pages
  10. sed -e s/data-inbound-url\=//g -i ./www.reddit.com/r/$1/top/index.html\?\sort\=\top\&t\=$2\&limit\=$3
  11.  
  12. # Fixes paths to comment page html files so that it can be copied to the script's directory
  13. sed -i 's/href\=\"\.\.\//href\=\"www.reddit.com\/r\/'$1'\//g' -i ./www.reddit.com/r/$1/top/index.html\?\sort\=\top\&t\=$2\&limit\=$3
  14.  
  15. #Setting variable for the subsequent filename
  16. fulldate="$(date +%m-%d-%y)"
  17.  
  18. # Copies the main html file to a file in the script's directory for easier access
  19. cp ./www.reddit.com/r/$1/top/index.html\?\sort\=\top\&t\=$2\&limit\=$3 $1" - Top "$3" from "$2" - "$fulldate".html"
Add Comment
Please, Sign In to add comment