mirror of
https://github.com/hughrun/ephemetoot
synced 2025-02-16 19:50:35 +01:00
commit
999abcb934
@ -44,6 +44,8 @@ You can use `ephemetoot` to delete [Mastodon](https://github.com/tootsuite/masto
|
||||
* they are individually listed to be kept
|
||||
|
||||
## Contributing
|
||||
ephemetoot is packaged using `poetry` and tested using `pytest`.
|
||||
|
||||
For all bugs, suggestions, pull requests or other contributions, please check the [contributing guide](./docs/contributing.md).
|
||||
|
||||
## License
|
||||
|
@ -380,9 +380,9 @@ def print_rate_limit_message(mastodon):
|
||||
)
|
||||
|
||||
|
||||
def retry_on_error(options, mastodon, toot, attempts):
|
||||
def retry_on_error(options, mastodon, toot, attempts=0):
|
||||
|
||||
if attempts < 6:
|
||||
if attempts < 6:
|
||||
try:
|
||||
console_print(
|
||||
"Attempt " + str(attempts) + " at " + datestamp_now(), options, False
|
||||
@ -396,7 +396,7 @@ def retry_on_error(options, mastodon, toot, attempts):
|
||||
raise TimeoutError("Gave up after 5 attempts")
|
||||
|
||||
|
||||
def process_toot(config, options, mastodon, deleted_count, toot):
|
||||
def process_toot(config, options, mastodon, toot, deleted_count=0):
|
||||
|
||||
keep_pinned = "keep_pinned" in config and config["keep_pinned"]
|
||||
toots_to_keep = config["toots_to_keep"] if "toots_to_keep" in config else []
|
||||
@ -531,7 +531,7 @@ def check_batch(config, options, mastodon, user_id, timeline, deleted_count=0):
|
||||
try:
|
||||
for toot in timeline:
|
||||
# process_toot returns the value of the deleted_count so we can keep track here
|
||||
deleted_count = process_toot(config, options, mastodon, deleted_count, toot)
|
||||
deleted_count = process_toot(config, options, mastodon, toot, deleted_count)
|
||||
|
||||
# the account_statuses call is paginated with a 40-toot limit
|
||||
# get the id of the last toot to include as 'max_id' in the next API call.
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "ephemetoot"
|
||||
version = "3.1.0"
|
||||
version = "3.1.1a1"
|
||||
description = "A command line tool to delete your old toots"
|
||||
authors = ["Hugh Rundle <ephemetoot@hugh.run>"]
|
||||
license = "GPL-3.0-or-later"
|
||||
@ -15,6 +15,7 @@ classifiers = [
|
||||
]
|
||||
include = [
|
||||
"LICENSE",
|
||||
"tests"
|
||||
]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
|
@ -233,7 +233,7 @@ def test_check_batch(capfd, monkeypatch):
|
||||
# this simulates what would happen if the toot was being deleted
|
||||
monkeypatch.setattr(
|
||||
"ephemetoot.ephemetoot.process_toot",
|
||||
lambda config, options, mastodon, deleted_count, toot: deleted_count + 1,
|
||||
lambda config, options, mastodon, toot, deleted_count: deleted_count + 1,
|
||||
)
|
||||
# run check_batch
|
||||
ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0)
|
||||
@ -249,7 +249,7 @@ def test_check_batch_quiet(capfd, monkeypatch):
|
||||
timeline = mastodon.account_statuses(user_id=user_id, limit=2, max_id=0)
|
||||
monkeypatch.setattr(
|
||||
"ephemetoot.ephemetoot.process_toot",
|
||||
lambda config, options, mastodon, deleted_count, toot: deleted_count + 1,
|
||||
lambda config, options, mastodon, toot, deleted_count: deleted_count + 1,
|
||||
)
|
||||
ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0)
|
||||
# deleted_count should be 10
|
||||
@ -265,7 +265,7 @@ def test_check_batch_quiet_no_toots(capfd, monkeypatch):
|
||||
timeline = mastodon.account_statuses(user_id=user_id, limit=2, max_id=10)
|
||||
monkeypatch.setattr(
|
||||
"ephemetoot.ephemetoot.process_toot",
|
||||
lambda config, options, mastodon, deleted_count, toot: deleted_count + 1,
|
||||
lambda config, options, mastodon, toot, deleted_count: deleted_count + 1,
|
||||
)
|
||||
# run check_batch
|
||||
ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0)
|
||||
@ -281,7 +281,7 @@ def test_check_batch_qq(capfd, monkeypatch):
|
||||
timeline = mastodon.account_statuses(user_id=user_id, limit=2, max_id=0)
|
||||
monkeypatch.setattr(
|
||||
"ephemetoot.ephemetoot.process_toot",
|
||||
lambda config, options, mastodon, deleted_count, toot: deleted_count + 1,
|
||||
lambda config, options, mastodon, toot, deleted_count: deleted_count + 1,
|
||||
)
|
||||
ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0)
|
||||
# deleted_count should be 10 and message printed since there was a delete
|
||||
@ -297,7 +297,7 @@ def test_check_batch_qq_no_deletes(capfd, monkeypatch):
|
||||
# simulate no deletes occuring
|
||||
monkeypatch.setattr(
|
||||
"ephemetoot.ephemetoot.process_toot",
|
||||
lambda config, options, mastodon, deleted_count, toot: 0,
|
||||
lambda config, options, mastodon, toot, deleted_count: 0,
|
||||
)
|
||||
# run check_batch
|
||||
ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0)
|
||||
@ -313,7 +313,7 @@ def test_check_batch_qqq(capfd, monkeypatch):
|
||||
timeline = mastodon.account_statuses(user_id=user_id, limit=2, max_id=0)
|
||||
monkeypatch.setattr(
|
||||
"ephemetoot.ephemetoot.process_toot",
|
||||
lambda config, options, mastodon, deleted_count, toot: deleted_count + 1,
|
||||
lambda config, options, mastodon, toot, deleted_count: deleted_count + 1,
|
||||
)
|
||||
# run check_batch
|
||||
ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0)
|
||||
@ -377,7 +377,6 @@ def test_init_archive_path(tmpdir):
|
||||
os.path.join(good_path, "/bad/path/"), "Archive path", None
|
||||
)
|
||||
ok = ephemetoot.sanitise_input(good_path, "Archive path", None)
|
||||
also_ok = ephemetoot.sanitise_input("~/Desktop", "Archive path", None)
|
||||
|
||||
assert ok == "ok"
|
||||
assert wrong == "That directory does not exist, please try again"
|
||||
@ -423,7 +422,6 @@ def test_init_sanitise_tag_list():
|
||||
def test_init_sanitise_url():
|
||||
tags = ("\033[96m", "\033[2m", "\033[0m")
|
||||
wrong = ephemetoot.sanitise_input("http://example.social", "Base URL", tags)
|
||||
also_wrong = ephemetoot.sanitise_input("http://example.social", "Base URL", tags)
|
||||
ok = ephemetoot.sanitise_input("example.social", "Base URL", tags)
|
||||
|
||||
assert (
|
||||
@ -476,7 +474,7 @@ def test_process_toot(capfd, tmpdir, monkeypatch):
|
||||
toot_dict["visibility"] = "public"
|
||||
toot_dict["reblog"] = False
|
||||
toot = dict2obj(toot_dict)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, 0, toot)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, toot, 0)
|
||||
assert (
|
||||
capfd.readouterr().out
|
||||
== "❌ deleting toot 104136090490756999 tooted 09 May 2020\n"
|
||||
@ -492,7 +490,7 @@ def test_process_toot_pinned(capfd, tmpdir):
|
||||
mastodon = Mocktodon()
|
||||
toot_dict["pinned"] = True
|
||||
toot = dict2obj(toot_dict)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, 0, toot)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, toot, 0)
|
||||
assert capfd.readouterr().out == "📌 skipping pinned toot - 104136090490756999\n"
|
||||
|
||||
|
||||
@ -506,7 +504,7 @@ def test_process_toot_saved(capfd, tmpdir):
|
||||
mastodon = Mocktodon()
|
||||
toot_dict["pinned"] = False
|
||||
toot = dict2obj(toot_dict)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, 0, toot)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, toot, 0)
|
||||
assert capfd.readouterr().out == "💾 skipping saved toot - 104136090490756999\n"
|
||||
|
||||
|
||||
@ -522,7 +520,7 @@ def test_process_toot_visibility(capfd, tmpdir):
|
||||
toot_dict["pinned"] = False # is true above so make false
|
||||
toot_dict["visibility"] = "testing"
|
||||
toot = dict2obj(toot_dict)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, 0, toot)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, toot, 0)
|
||||
assert capfd.readouterr().out == "👀 skipping testing toot - 104136090490756999\n"
|
||||
|
||||
|
||||
@ -540,7 +538,7 @@ def test_process_toot_hashtag(capfd, tmpdir, monkeypatch):
|
||||
toot_dict["reblog"] = True
|
||||
toot = dict2obj(toot_dict)
|
||||
|
||||
ephemetoot.process_toot(config_file, options, mastodon, 0, toot)
|
||||
ephemetoot.process_toot(config_file, options, mastodon, toot, 0)
|
||||
assert (
|
||||
capfd.readouterr().out
|
||||
== "👎 unboosting toot 104136090490756999 boosted 09 May 2020\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user