Format every in announce show.
authorCMDR furrycat <elite@furrycat.net>
Wed, 19 Oct 2016 21:53:02 +0000 (22:53 +0100)
committerCMDR furrycat <elite@furrycat.net>
Wed, 19 Oct 2016 21:53:02 +0000 (22:53 +0100)
bot.py

diff --git a/bot.py b/bot.py
index 3e1cca7..55c2689 100755 (executable)
--- a/bot.py
+++ b/bot.py
@@ -130,6 +130,24 @@ def parse_seconds(formatted):
 
   return seconds
 
+def unparse_seconds(seconds):
+  interval = ''
+  if seconds > 86400:
+    d = math.floor(seconds / 86400)
+    interval += '{}d'.format(d)
+    seconds -= d * 86400
+  if seconds > 3600:
+    h = math.floor(seconds / 3600)
+    interval += '{}h'.format(h)
+    seconds -= h * 3600
+  if seconds > 60:
+    m = math.floor(seconds / 60)
+    interval += '{}m'.format(m)
+    seconds -= h * 60
+  if seconds:
+    interval += '{}s'.format(seconds)
+  return interval
+
 def open_url(url):
   if sys.version_info >= (3, 0):
     # Specify our own user agent as Cloudflare doesn't seem to like the urllib one
@@ -1112,7 +1130,7 @@ def show_announcement(message, id):
   if announcement['end_date']:
     text += ' to "{}"'.format(iso8601(announcement['end_date']))
   if announcement['interval']:
-    text += ' every {}s'.format(announcement['interval'])
+    text += ' every {}'.format(unparse_seconds(int(announcement['interval'])))
   mention = announcement['mention']
   if mention:
     if mention == 'everyone' or mention == 'here':