feat: skip pins/favs
All checks were successful
continuous-integration/drone/push Build is passing

See #4
This commit is contained in:
decentral1se 2024-08-05 23:47:21 +02:00
parent 7876ce8632
commit 9383cce16d
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 18 additions and 4 deletions

BIN
blurp

Binary file not shown.

View File

@ -22,10 +22,12 @@ import (
)
var (
user string // account username
weeks int // number of weeks of statuses to retain
rate int // requests per second
dry bool // whether or not to run in dry mode
user string // account username
weeks int // number of weeks of statuses to retain
rate int // requests per second
dry bool // whether or not to run in dry mode
skipFavourites bool // whether or not to skip deleting favourites
skipPinned bool // whether or not to skip deleting pinned statuses
)
func init() {
@ -38,6 +40,8 @@ func init() {
deleteCmd.Flags().IntVarP(&weeks, "weeks", "w", 2, "keep statuses NEWER than no. of weeks")
deleteCmd.Flags().IntVarP(&rate, "rate", "r", 1, "send a request every 'r' seconds")
deleteCmd.Flags().BoolVarP(&dry, "dry", "d", false, "dry run mode (NO DELETION)")
deleteCmd.Flags().BoolVarP(&skipFavourites, "skip-favourites", "f", false, "skip deletion of favourites")
deleteCmd.Flags().BoolVarP(&skipPinned, "skip-pinnned", "p", false, "skip deletion of pinned statuses")
rootCmd.AddCommand(deleteCmd)
}
@ -177,6 +181,11 @@ var deleteCmd = &cobra.Command{
os.Exit(1)
}
if status.Favourited && skipFavourites {
slog.Info(fmt.Sprintf("skipping %s (skip favourites: %v)", status.ID, skipFavourites))
continue
}
numHours := time.Duration(168 * weeks)
if t.Before(time.Now().Add(-time.Hour * numHours)) {
if !dry {
@ -275,6 +284,11 @@ func readAllPaged(authClient *auth.Client, accID string) ([]*models.Status, erro
}
params := &accounts.AccountStatusesParams{ID: accID, MaxID: maxID}
if skipPinned {
includePins := false
params.Pinned = &includePins
}
resp, err := authClient.Client.Accounts.AccountStatuses(params, authClient.Auth)
if err != nil {
slog.Error("error fetching page", "error", err)