Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
19 changes: 19 additions & 0 deletions get_post_contents.sh
Original file line number Diff line number Diff line change
@@ -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 "<a HREF=\"saved-post-data/${post_tag}\"> (link to json backup of post)</a>" >> export-with-contents.html
fi
done