schedule cleanup and added --date option

This commit is contained in:
cottongin 2019-01-04 17:11:23 -06:00
parent fc7f7b4fbe
commit 5bd131294f
1 changed files with 16 additions and 3 deletions

View File

@ -260,9 +260,10 @@ class TVMaze(callbacks.Plugin):
'tz': 'somethingWithoutSpaces',
'network': 'somethingWithoutSpaces',
'country': 'somethingWithoutSpaces',
'date': 'somethingWithoutSpaces',
'showEpisodeTitle': ''})])
def schedule(self, irc, msg, args, options):
"""[--all | --tz <IANA timezone> | --network <network> | --country <country>]
"""[--all | --tz <IANA timezone> | --network <network> | --country <country> | --date <YYYY-MM-DD>]
Fetches upcoming TV schedule from TVMaze.com.
"""
# prefer manually passed options, then saved user options
@ -274,6 +275,7 @@ class TVMaze(callbacks.Plugin):
# parse manually passed options, if any
tz = options.get('tz') or 'US/Eastern'
country = options.get('country')
date = options.get('date')
# TO-DO: add a --filter option(s)
if country:
country = country.upper()
@ -290,8 +292,14 @@ class TVMaze(callbacks.Plugin):
country = 'US'
# we don't need to default tz here because it's already set
# parse date input
if date:
date = pendulum.parse(date, strict=False).format('YYYY-MM-DD')
else:
date = pendulum.now(tz).format('YYYY-MM-DD')
# fetch the schedule
schedule_data = self._get('schedule', country=country)
schedule_data = self._get('schedule', country=country, date=date)
if not schedule_data:
irc.reply('Something went wrong fetching TVMaze schedule data.')
@ -329,11 +337,16 @@ class TVMaze(callbacks.Plugin):
# for now, defaults to only upcoming 'Scripted' shows
if show['show']['type'] == 'Scripted' and pendulum.now(tz) <= time:
shows.append(tmp)
# set a default message if no shows were found
if not shows:
shows.append('No upcoming shows found')
# finally reply
reply = "{}: {}".format(self._ul("Today's Shows"), ", ".join(shows))
irc.reply(reply)
@wrap([getopts({'country': 'somethingWithoutSpaces',
'tz': 'somethingWithoutSpaces',
'showEpisodeTitle': 'boolean',