Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbanchich authored Jun 25, 2023
2 parents ced9175 + 4a80f0a commit 40d708a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ Options:
The User-Agent for Reddit API requests [env: SHREDDIT_USER_AGENT=ShredditRustClient] [default: ShredditRustClient]
--gdpr-export-dir <GDPR_EXPORT_DIR>
The path of the directory of the unzipped GDPR export data. If set, `shreddit` will use the GDPR export folder instead of Reddit's APIs for discovering your data [env: SHREDDIT_GDPR_EXPORT_DIR=/home/you/Downloads/export_yourusername_20230101]
--replacement_comment<REPLACEMENT_CMMENT>
This allows you to customize the text every comment will be edited into prior to deletion.
[env: SHREDDIT_REPLACEMENT_COMMENT="Long Live 3rd Party Apps!"]
--edit_only
When set 'true', no items will be deleted. Items (comments) will still be modified though.
[env = SHREDDIT_EDIT_ONLY=true/false, default_value = false]
-h, --help
Print help
-V, --version
Expand Down
1 change: 1 addition & 0 deletions shreddit.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ SHREDDIT_THING_TYPES=posts,comments
SHREDDIT_BEFORE='2023-01-01T00:00:00Z'
SHREDDIT_MAX_SCORE=100
SHREDDIT_USER_AGENT='ShredditRustClient'
SHREDDIT_EDIT_ONLY=false
SHREDDIT_GDPR_EXPORT_DIR='/home/you/Downloads/export_yourusername_20230101'
25 changes: 25 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::things::{ThingType, LOREM_IPSUM};
use chrono::{DateTime, Utc};
use clap::Parser;
use std::path::PathBuf;
use tracing::{debug, warn};

#[derive(Debug, Parser)]
#[clap(author, version, about)]
Expand Down Expand Up @@ -56,4 +57,28 @@ pub struct Config {
/// Reddit's APIs for discovering your data.
#[clap(long, env = "SHREDDIT_GDPR_EXPORT_DIR")]
pub gdpr_export_dir: Option<PathBuf>,

/// If specified, comments will only be edited, not deleted. - Requires gdpr_export
#[clap(long, env = "SHREDDIT_EDIT_ONLY")]
pub edit_only: bool,
}

impl Config {
/// Return TRUE if either edit_only or dr_run
pub fn should_prevent_deletion(&self) -> bool {
if self.edit_only {
debug!(
"Skipping DELETION due to `edit_only` filter ({})",
self.edit_only
);
if self.gdpr_export_dir.is_none() {
// As of this writing, there is an approx 1000 comment limit when pulling from JSON. Only reliable way to reach all data is via GDPR.
// See issue #35: https://github.com/andrewbanchich/shreddit/issues/35
warn!("Because you are not using a GDPR export, not all data will be reached.\nFor info on how to use a GDPR export, see: {}", r##"https://github.com/andrewbanchich/shreddit#delete-all-your-data-using-gdpr-export"##);
}
} else if self.dry_run {
debug!("Skipping DELETION due to 'dry run' filter");
}
return self.edit_only | self.dry_run;
}
}
6 changes: 1 addition & 5 deletions src/things/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ impl Shred for Comment {
async fn delete(&self, client: &Client, access_token: &str, config: &Config) {
info!("Deleting...");

if self.should_skip(config) {
return;
}

if config.dry_run {
if self.should_skip(config) || config.should_prevent_deletion() {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/things/friend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Shred for Friend {
async fn delete(&self, client: &Client, access_token: &str, config: &Config) {
info!("Deleting...");

if config.dry_run {
if config.should_prevent_deletion() {
return;
}

Expand Down
6 changes: 1 addition & 5 deletions src/things/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ impl Shred for Post {
async fn delete(&self, client: &Client, access_token: &str, config: &Config) {
info!("Deleting...");

if self.should_skip(config) {
return;
}

if config.dry_run {
if self.should_skip(config) || config.should_prevent_deletion() {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/things/saved_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Shred for SavedComment {
// return;
// }

if config.dry_run {
if config.should_prevent_deletion() {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/things/saved_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Shred for SavedPost {
// return;
// }

if config.dry_run {
if config.should_prevent_deletion() {
return;
}

Expand Down

0 comments on commit 40d708a

Please sign in to comment.