Skip to content

Commit e05db69

Browse files
committed
Fix handling of missing duration.
Also reformatted/fixed a couple minor things. This resolves #90.
1 parent b4d526c commit e05db69

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

β€Žtweet_delete/deleter.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,12 @@ def check_and_remove_favorites(self):
257257
max_id = None
258258
favorites_read = 0
259259

260-
click.echo(click.style("checking for favorites", fg="cyan",))
260+
click.echo(
261+
click.style(
262+
"checking for favorites",
263+
fg="cyan",
264+
)
265+
)
261266

262267
while has_favourites:
263268
has_favourites = False
@@ -300,7 +305,10 @@ def check_and_remove_favorites(self):
300305

301306
def delete_favourite(self, fav):
302307
click.echo(
303-
click.style("deleting favorite with ID={}".format(fav.id), fg="blue",)
308+
click.style(
309+
"deleting favorite with ID={}".format(fav.id),
310+
fg="blue",
311+
)
304312
)
305313
self.api.DestroyFavorite(status_id=fav.id)
306314
if fav.id in self.favourites_scheduled_for_deletion:
@@ -327,4 +335,4 @@ def run(self):
327335
delay = min([delay, 300])
328336
click.echo(click.style("caught exception: {}".format(e), fg="red"))
329337
click.echo(click.style("will retry in {}s".format(delay), fg="red"))
330-
gevent.sleep(delay)
338+
gevent.sleep(int(delay))

β€Žtweet_delete/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ def validate_duration(ctx, param, value):
1414
from pytimeparse import parse
1515

1616
seconds = parse(value)
17-
if seconds <= 0:
18-
raise click.BadParameter("Duration should be greater than 0")
17+
if not seconds or seconds <= 0:
18+
raise click.BadParameter(
19+
"Duration must be specified and should be greater than 0"
20+
)
1921
return datetime.timedelta(seconds=seconds)
2022
except ValueError:
21-
raise click.BadParameter("Invalid duration (try '24h' or '7 days'")
23+
raise click.BadParameter(
24+
"Invalid duration (try '60s', '24h' or '7 days'. "
25+
"See https://github.com/wroberts/pytimeparse for valid expressions."
26+
)
2227

2328

2429
def validate_datetime(ctx, param, value):
@@ -127,7 +132,10 @@ def cli(
127132
)
128133
else:
129134
click.echo(
130-
click.style("πŸ‘‰ favorites will NOT be deleted".ljust(77) + "πŸ‘ˆ", fg="yellow",)
135+
click.style(
136+
"πŸ‘‰ favorites will NOT be deleted".ljust(77) + "πŸ‘ˆ",
137+
fg="yellow",
138+
)
131139
)
132140
click.echo(click.style("πŸ¦… off we go".ljust(77) + "πŸ¦…", fg="green"))
133141
deleter.run()

0 commit comments

Comments
Β (0)