2020-04-20 12:14:58 +02:00
#!/usr/bin/env python3
# #####################################################################
2020-08-26 13:59:01 +02:00
# Ephemetoot - A command line tool to delete your old toots
# Copyright (C) 2018 Hugh Rundle, 2019-2020 Hugh Rundle & others
2020-04-20 12:14:58 +02:00
# Initial work based on tweet-deleting script by @flesueur
# (https://gist.github.com/flesueur/bcb2d9185b64c5191915d860ad19f23f)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2020-08-26 13:59:01 +02:00
# You can contact Hugh on Mastodon: @hugh@ausglam.space
# or email: ephemetoot@hugh.run
2020-04-20 12:14:58 +02:00
# #####################################################################
# import
import yaml
# from standard library
from argparse import ArgumentParser
2020-06-20 12:52:34 +02:00
from datetime import datetime , timezone
2020-04-20 12:14:58 +02:00
import os
2020-06-21 07:25:04 +02:00
import pkg_resources
2020-04-20 12:14:58 +02:00
2020-08-26 13:59:01 +02:00
# import funtions
from ephemetoot import ephemetoot as func
2020-04-20 12:14:58 +02:00
2020-08-26 13:59:01 +02:00
# version number from package info
2020-06-21 07:25:04 +02:00
vnum = pkg_resources . require ( " ephemetoot " ) [ 0 ] . version
2020-04-20 12:14:58 +02:00
parser = ArgumentParser ( )
2020-07-18 09:38:16 +02:00
parser . add_argument (
" --archive-deleted " , action = " store_true " , help = " Only archive toots that are being deleted "
)
2020-04-20 12:14:58 +02:00
parser . add_argument (
2020-07-18 07:44:00 +02:00
" --config " , action = " store " , metavar = " filepath " , default = " config.yaml " , help = " Filepath of your config file, absolute or relative to the current directory. If no --config path is provided, ephemetoot will use ' config.yaml ' . "
2020-04-20 12:14:58 +02:00
)
parser . add_argument (
2020-06-21 05:59:30 +02:00
" --datestamp " , action = " store_true " , help = " Include a datetime stamp for every action (e.g. deleting a toot) "
2020-04-20 12:14:58 +02:00
)
2020-06-20 13:05:06 +02:00
parser . add_argument (
2020-07-18 09:38:16 +02:00
" --hide-skipped " , " --hide_skipped " , action = " store_true " , help = " Do not write to log when skipping saved toots "
2020-06-20 13:05:06 +02:00
)
2020-08-28 10:16:39 +02:00
parser . add_argument (
" --init " , action = " store_true " , help = " Initialise creation of a config file saved in the current directory. "
)
2020-06-21 04:42:25 +02:00
parser . add_argument (
" --pace " , action = " store_true " , help = " Slow deletion actions to match API rate limit to avoid pausing "
)
2020-07-18 10:02:30 +02:00
parser . add_argument (
" --quiet " , action = " store_true " , help = " Suppress most logging "
)
2020-08-23 08:53:03 +02:00
parser . add_argument (
" --retry-mins " , action = " store " , metavar = " minutes " , nargs = " ? " , const = " 1 " , default = " 1 " , type = int , help = " Number of minutes to wait between retries, when an error is thrown "
)
2020-04-25 00:53:19 +02:00
parser . add_argument (
2020-07-18 07:44:00 +02:00
" --schedule " , action = " store " , metavar = " filepath " , nargs = " ? " , const = " . " , help = " Save and load plist file on MacOS "
2020-04-25 00:53:19 +02:00
)
2020-06-20 12:52:34 +02:00
parser . add_argument (
2020-06-21 05:59:30 +02:00
" --test " , action = " store_true " , help = " Do a test run without deleting any toots "
2020-06-20 12:52:34 +02:00
)
2020-04-25 00:53:19 +02:00
parser . add_argument (
2020-07-18 07:44:00 +02:00
" --time " , action = " store " , metavar = ( ' hour ' , ' minute ' ) , nargs = " * " , help = " Hour and minute to schedule: e.g. 9 30 for 9.30am "
2020-04-25 00:53:19 +02:00
)
2020-06-21 07:25:04 +02:00
parser . add_argument (
" --version " , action = " store_true " , help = " Display the version number "
)
2020-04-20 12:14:58 +02:00
options = parser . parse_args ( )
if options . config [ 0 ] == ' ~ ' :
config_file = os . path . expanduser ( options . config )
elif options . config [ 0 ] == ' / ' :
config_file = options . config
else :
config_file = os . path . join ( os . getcwd ( ) , options . config )
2020-08-26 13:59:01 +02:00
def main ( ) :
2020-08-28 10:16:39 +02:00
if options . init :
func . init ( )
elif options . version :
2020-08-26 13:59:01 +02:00
func . version ( vnum )
2020-06-21 07:25:04 +02:00
elif options . schedule :
2020-08-26 13:59:01 +02:00
func . schedule ( options )
2020-04-25 00:53:19 +02:00
else :
2020-07-18 10:02:30 +02:00
if not options . quiet :
print ( ' ' )
print ( ' ============= EPHEMETOOT v ' + vnum + ' ================ ' )
print ( ' Running at ' + str ( datetime . now ( timezone . utc ) . strftime ( ' %a %d % b % Y % H: % M: % S % z ' ) ) )
print ( ' ================================================ ' )
print ( ' ' )
2020-04-27 07:28:07 +02:00
if options . test :
2020-07-18 09:38:16 +02:00
print ( " This is a test run... \n " )
2020-04-25 00:53:19 +02:00
with open ( config_file ) as config :
for accounts in yaml . safe_load_all ( config ) :
for user in accounts :
2020-08-26 13:59:01 +02:00
func . checkToots ( user , options )
if __name__ == ' __main__ ' :
main ( )