ttbp/bin/util.py
endorphant cbbdb1e8b7 mail and code cleanup
_ttbp.py is now the working copy i'm using, so i don't bust the live
program.

i brought over the id code generator that i use in txtminebot to
generate random id tags for feedback subject lines. the feedback
mechanism now uses sendmail instead of writing to disk.

i also started to clean up some of the larger text blocks by using here
documents.
2016-05-14 23:44:03 -04:00

42 lines
889 B
Python

#!/usr/bin/python
import inflect
import time
import random
p = inflect.engine()
def pretty_time(time):
m, s = divmod(time, 60)
if m > 0:
h, m = divmod(m, 60)
if h > 0:
d, h = divmod(h, 24)
if d > 0:
w, d = divmod(d, 7)
if w > 0:
mo, w = divmod(w, 4)
if mo > 0:
return p.no("month", mo)
else:
return p.no("week", w)
else:
return p.no("day", d)
else:
return p.no("hour", h)
else:
return p.no("minute", m)
else:
return p.no("second", s)
def genID(digits=5):
# makes a string of digits
id = ""
x = 0
while x < digits:
id += str(random.randint(0,9))
x += 1
return id