Merge pull request #83 from Atheuz/development
tvdb.py: When there's a next episode date, provide a time until in the return string.
This commit is contained in:
commit
771118f0c7
|
@ -9,7 +9,7 @@ from zipfile import ZipFile
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from util import hook, http
|
from util import hook, http, timesince
|
||||||
|
|
||||||
|
|
||||||
base_url = "http://thetvdb.com/api/"
|
base_url = "http://thetvdb.com/api/"
|
||||||
|
@ -60,10 +60,10 @@ def get_episodes_for_series(seriesname):
|
||||||
|
|
||||||
|
|
||||||
def get_episode_info(episode):
|
def get_episode_info(episode):
|
||||||
first_aired = episode.findtext("FirstAired")
|
episode_air_date = episode.findtext("FirstAired")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
airdate = datetime.date(*map(int, first_aired.split('-')))
|
airdate = datetime.date(*map(int, episode_air_date.split('-')))
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ def get_episode_info(episode):
|
||||||
episode_desc = '%s' % episode_num
|
episode_desc = '%s' % episode_num
|
||||||
if episode_name:
|
if episode_name:
|
||||||
episode_desc += ' - %s' % episode_name
|
episode_desc += ' - %s' % episode_name
|
||||||
return (first_aired, airdate, episode_desc)
|
return (episode_air_date, airdate, episode_desc)
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
|
@ -107,10 +107,10 @@ def tv_next(inp):
|
||||||
if ep_info is None:
|
if ep_info is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
(first_aired, airdate, episode_desc) = ep_info
|
(episode_air_date, airdate, episode_desc) = ep_info
|
||||||
|
|
||||||
if airdate > today:
|
if airdate > today:
|
||||||
next_eps = ['%s (%s)' % (first_aired, episode_desc)]
|
next_eps = ['%s (%s) (%s)' % (episode_air_date, timesince.timeuntil(datetime.datetime.strptime(episode_air_date, "%Y-%m-%d")), episode_desc)]
|
||||||
elif airdate == today:
|
elif airdate == today:
|
||||||
next_eps = ['Today (%s)' % episode_desc] + next_eps
|
next_eps = ['Today (%s)' % episode_desc] + next_eps
|
||||||
else:
|
else:
|
||||||
|
@ -150,12 +150,12 @@ def tv_last(inp):
|
||||||
if ep_info is None:
|
if ep_info is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
(first_aired, airdate, episode_desc) = ep_info
|
(episode_air_date, airdate, episode_desc) = ep_info
|
||||||
|
|
||||||
if airdate < today:
|
if airdate < today:
|
||||||
#iterating in reverse order, so the first episode encountered
|
#iterating in reverse order, so the first episode encountered
|
||||||
#before today was the most recently aired
|
#before today was the most recently aired
|
||||||
prev_ep = '%s (%s)' % (first_aired, episode_desc)
|
prev_ep = '%s (%s)' % (episode_air_date, episode_desc)
|
||||||
break
|
break
|
||||||
|
|
||||||
if not prev_ep:
|
if not prev_ep:
|
||||||
|
|
Loading…
Reference in New Issue