From cfd4bad1ef700da1e029654d648e709b72b1d2aa Mon Sep 17 00:00:00 2001 From: ZapperDJ Date: Thu, 3 Nov 2022 17:44:32 +0100 Subject: [PATCH 1/2] Add script to unsave posts --- scripts/unsaveposts.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/unsaveposts.py diff --git a/scripts/unsaveposts.py b/scripts/unsaveposts.py new file mode 100644 index 0000000..c332520 --- /dev/null +++ b/scripts/unsaveposts.py @@ -0,0 +1,40 @@ +#! /usr/bin/env python3.9 +''' +This script takes a list of submission IDs from a file named "successfulids" created with the +"extract_successful_ids.sh" script and unsaves them from your account. To make it work you must +fill in the username and password fields below. Make sure you keep the quotes around the fields. +You'll need to make a "user script" in your reddit profile to run this. +Go to https://old.reddit.com/prefs/apps/ +Click on "Develop an app" at the bottom. +Make sure you select a "script" not a "web app." +Give it a random name. Doesn't matter. +You need to fill in the "Redirect URI" field with something so go ahead and put 127.0.0.0 in there. +Save it. +The client ID is the 14 character string under the name you gave your script. +It'll look like a bunch of random characters like this: pspYLwDoci9z_A +The client secret is the longer string next to "secret". +Replace those two fields below. Again keep the quotes around the fields. +''' + +import praw + +try: + r= praw.Reddit( + client_id="CLIENTID", + client_secret="CLIENTSECRET", + password="USERPASSWORD", + user_agent="Unsave Posts", + username="USERNAME", + ) + + with open("successfulids", "r") as f: + for item in f: + r.submission(id = item.strip()).unsave() + +except: + print("Something went wrong. Did you install PRAW? Did you change the user login fields?") + + +else: + print("Done! Thanks for playing!") + From 66049a402185a117297e9ec3daa9100c8ffe4fa2 Mon Sep 17 00:00:00 2001 From: ZapperDJ Date: Mon, 19 Dec 2022 16:54:09 +0100 Subject: [PATCH 2/2] Add documentation for unsavepost.py --- README.md | 4 ++++ scripts/README.md | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 2c245c6..204e76f 100644 --- a/README.md +++ b/README.md @@ -391,6 +391,10 @@ The way to fix this is to use the `--log` option to manually specify where the l The logfiles that the BDFR outputs are consistent and quite detailed and in a format that is amenable to regex. To this end, a number of bash scripts have been [included here](./scripts). They show examples for how to extract successfully downloaded IDs, failed IDs, and more besides. +## Unsaving posts + +Back in v1 there was an option to unsave posts from your account when downloading, but it was removed from the core BDFR on v2 as it is considered a read-only tool. However, for those missing this functionality, a script was created that uses the log files to achieve this. There is info on how to use this on the README.md file on the scripts subdirectory. + ## List of currently supported sources - Direct links (links leading to a file) diff --git a/scripts/README.md b/scripts/README.md index 4bb098b..b6e7c80 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -6,6 +6,7 @@ Due to the verboseness of the logs, a great deal of information can be gathered - [Script to extract all failed download IDs](#extract-all-failed-ids) - [Timestamp conversion](#converting-bdfrv1-timestamps-to-bdfrv2-timestamps) - [Printing summary statistics for a run](#printing-summary-statistics) + - [Unsaving posts from your account after downloading](#unsave-posts-after-downloading) ## Extract all Successfully Downloaded IDs @@ -67,3 +68,23 @@ Excluded submissions: 1146 Files with existing hash skipped: 0 Submissions from excluded subreddits: 0 ``` + +## Unsave Posts After Downloading + +[This script](unsaveposts.py) takes a list of submission IDs from a file named `successfulids` created with the `extract_successful_ids.sh` script and unsaves them from your account. To make it work you will need to make a user script in your reddit profile like this: + - Fill in the username and password fields in the script. Make sure you keep the quotes around the fields. + - Go to https://old.reddit.com/prefs/apps/ + - Click on `Develop an app` at the bottom. + - Make sure you select a `script` not a `web app`. + - Name it `Unsave Posts`. + - Fill in the `Redirect URI` field with `127.0.0.0`. + - Save it. + - Fill in the `client_id` and `client_secret` fields on the script. The client ID is the 14 character string under the name you gave your script. .It'll look like a bunch of random characters like this: pspYLwDoci9z_A. The client secret is the longer string next to "secret". Again keep the quotes around the fields. + +Now the script is ready tu run. Just execute it like this: + +```bash +python3.9 -m bdfr download DOWNLOAD_DIR --authenticate --user me --saved --log LOGFILE_LOCATION +./extract_successful_ids.sh LOGFILE_LOCATION > successfulids +./unsaveposts.py +```