Browse Source

gains --slot-size

boyska 2 years ago
parent
commit
bd5aa7972f
1 changed files with 16 additions and 2 deletions
  1. 16 2
      ics2mdwn.py

+ 16 - 2
ics2mdwn.py

@@ -27,6 +27,13 @@ def get_parser():
         type=Path,
     )
     p.add_argument("--trust-location", type=str, nargs="*", default=[])
+    p.add_argument(
+        "--slot-size",
+        type=int,
+        metavar="MINUTES",
+        default=15,
+        help="Round times to the nearest */MINUTES",
+    )
     p.add_argument("--night-threshold", metavar="HOUR", default=5, type=int)
     p.add_argument("--mode", choices=["hugo"], default="hugo")
     return p
@@ -44,6 +51,13 @@ def round_down(num, divisor):
     return num - (num % divisor)
 
 
+def round_down_time(hhmm: str, divisor: int):
+    hh = hhmm[:-2]
+    mm = hhmm[-2:]
+    mm = round_down(int(mm, base=10), divisor)
+    return int('%s%02d' % (hh,mm) , base=10)
+
+
 class Converter:
     """
     This class takes care of everything converter-related.
@@ -164,10 +178,10 @@ class HugoConverter(Converter):
             room = self.talk_room[uid]
             days[day]["rooms"].setdefault(room, dict(room=room, slots=[]))
 
-            talkstart = round_down(hour * 100 + minute, 10)
+            talkstart = round_down_time('%02d%02d' % (hour, minute), self.args.slot_size)
             duration = talk.decoded("dtend") - talk.decoded("dtstart")
             duration_minutes = int(duration.total_seconds() // 60)
-            duration_minutes = round_down(duration_minutes, 30)
+            duration_minutes = round_down(duration_minutes, self.args.slot_size)
             slot = "%04d-%dmin" % (talkstart, duration_minutes)
             days[day]["rooms"][room]["slots"].append(dict(slot=slot, talk=uid))