changeset 11939:d1bee51ebc7e draft

<wob_jonas> fetch bin/beat https://hack.esolangs.org/get/bin/beat
author HackEso <hackeso@esolangs.org>
date Fri, 13 Sep 2019 12:13:46 +0000
parents 78fee00d2bd2
children 35d17fa5d3ba
files bin/beat
diffstat 1 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/bin/beat	Fri Sep 13 11:19:12 2019 +0000
+++ b/bin/beat	Fri Sep 13 12:13:46 2019 +0000
@@ -1,5 +1,19 @@
-#!/usr/bin/python3
-# beat - prints current Swatch Internet Time
-import math,time
-b = math.floor(((time.time()+3600) % 86400) / 86.4)
-print("%03d"%(b,))
+#!python3
+# beat - print current time in Swatch Internet Time format.
+# blame fizzie
+import math,sys,getopt,time
+prec = 0
+opts,args = getopt.getopt(sys.argv[1:], "hpP:")
+print(opts)
+for opt,oarg in opts:
+	if "-p" == opt: prec = 2
+	elif "-P" == opt: prec = int(oarg)
+	elif "-h" == opt: print("Usage: beat [-p]\nPrint current time in Swatch Internet Time format."); sys.exit(2)
+	else: raise AssertionError()
+if args:
+	raise RuntimeError("too many command-line arguments")
+b = math.floor(((time.time()+3600) % 86400) / 86.4 * 10**prec)
+o = "%0*d" % (prec, b)
+if 0 < prec: o = o[0:-prec] + "." + o[-prec:]
+print(o)
+#END