added variable accuracy to the time_format function (really should move this, huh)
This commit is contained in:
parent
a59becca73
commit
a37fc245d0
1 changed files with 5 additions and 5 deletions
|
@ -17,7 +17,7 @@ def plural(num=0, text=''):
|
||||||
return "{:,} {}{}".format(num, text, "s"[num==1:])
|
return "{:,} {}{}".format(num, text, "s"[num==1:])
|
||||||
|
|
||||||
|
|
||||||
def format_time(seconds, count=3, simple=False):
|
def format_time(seconds, count=3, accuracy=6, simple=False):
|
||||||
if simple:
|
if simple:
|
||||||
periods = [
|
periods = [
|
||||||
('c', 60 * 60 * 24 * 365 * 100),
|
('c', 60 * 60 * 24 * 365 * 100),
|
||||||
|
@ -41,6 +41,8 @@ def format_time(seconds, count=3, simple=False):
|
||||||
(('second', 'seconds'), 1)
|
(('second', 'seconds'), 1)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
periods = periods[-accuracy:]
|
||||||
|
|
||||||
strings = []
|
strings = []
|
||||||
i = 0
|
i = 0
|
||||||
for period_name, period_seconds in periods:
|
for period_name, period_seconds in periods:
|
||||||
|
@ -118,7 +120,6 @@ def youtube_url(match):
|
||||||
@hook.command
|
@hook.command
|
||||||
def youtube(inp):
|
def youtube(inp):
|
||||||
"""youtube <query> -- Returns the first YouTube search result for <query>."""
|
"""youtube <query> -- Returns the first YouTube search result for <query>."""
|
||||||
|
|
||||||
request = http.get_json(search_api_url, q=inp)
|
request = http.get_json(search_api_url, q=inp)
|
||||||
|
|
||||||
if 'error' in request:
|
if 'error' in request:
|
||||||
|
@ -137,7 +138,6 @@ def youtube(inp):
|
||||||
@hook.command
|
@hook.command
|
||||||
def youtime(inp):
|
def youtime(inp):
|
||||||
"""youtime <query> -- Gets the total run time of the first YouTube search result for <query>."""
|
"""youtime <query> -- Gets the total run time of the first YouTube search result for <query>."""
|
||||||
|
|
||||||
request = http.get_json(search_api_url, q=inp)
|
request = http.get_json(search_api_url, q=inp)
|
||||||
|
|
||||||
if 'error' in request:
|
if 'error' in request:
|
||||||
|
@ -161,7 +161,7 @@ def youtime(inp):
|
||||||
total = int(length * views)
|
total = int(length * views)
|
||||||
|
|
||||||
length_text = format_time(length, simple=True)
|
length_text = format_time(length, simple=True)
|
||||||
total_text = format_time(total)
|
total_text = format_time(total, accuracy=8)
|
||||||
|
|
||||||
return u'The video \x02{}\x02 has a length of {} and has been viewed {:,} times for ' \
|
return u'The video \x02{}\x02 has a length of {} and has been viewed {:,} times for ' \
|
||||||
'a total run time of {}!'.format(data['title'], length_text, views, \
|
'a total run time of {}!'.format(data['title'], length_text, views, \
|
||||||
|
|
Reference in a new issue