diff --git a/README.md b/README.md index 6ad1227..760f4fd 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ To install without git, [download the source code from GitHub](https://github.co -all, --all get upvoted, saved, comments and submissions -V, --version get program version. +## get-post-contents +I included a quick-and-dirty shell script that will pull a JSON backup of all your saved posts, and create a new HTML file that includes a link to the JSON backup. it isn't pretty and uses a browser user-agent, as well as going one-by-one, so be prepared to let it sit for a while + ## Updating To update the script to the latest version, enter the `export-saved-reddit` folder in your shell/command prompt and enter the following: diff --git a/get_post_contents.sh b/get_post_contents.sh new file mode 100755 index 0000000..4859cf9 --- /dev/null +++ b/get_post_contents.sh @@ -0,0 +1,19 @@ +#!/bin/bash +> export-with-contents.html +mkdir -p saved-post-data +htmlfile=export-saved.html +exec 4<${htmlfile} #open file descriptor to htmlfile (might be too big to read into memory) +while read -u4 line ; +do + echo "${line}" >> export-with-contents.html + if [[ ${line} == *"HREF"* ]] ; + then + + url=$(awk -F '"' '{print $2;}' <(echo "${line}")) + post_tag=$(echo "${url}" | sed 's/https:\/\/www.reddit.com//' | sed 's/\///g') + echo "getting post data for ${url} (writing data to saved-post-data/${post_tag})" + data=$(curl --silent -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" ${url}".json") + echo "${data}" > saved-post-data/${post_tag} + echo " (link to json backup of post)" >> export-with-contents.html + fi +done