Merge branch 'master' of MLBScores

This commit is contained in:
oddluck 2019-12-05 09:48:25 +00:00
commit b38877b90e
7 changed files with 4332 additions and 0 deletions

1
MLBScores/README.md Normal file
View File

@ -0,0 +1 @@
Plugin to fetch MLB scores from the MLB.com API

71
MLBScores/__init__.py Normal file
View File

@ -0,0 +1,71 @@
###
# Copyright (c) 2018, cottongin
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
"""
MLBScores: Plugin to fetch MLB scores from the MLB.com API
"""
import supybot
import supybot.world as world
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
__version__ = ""
# XXX Replace this with an appropriate author or supybot.Author instance.
__author__ = supybot.Author('cottongin', 'cottongin',
'cottongin@cottongin.club')
__maintainer__ = getattr(supybot.authors, 'oddluck',
supybot.Author('oddluck', 'oddluck', 'oddluck@riseup.net'))
# This is a dictionary mapping supybot.Author instances to lists of
# contributions.
__contributors__ = {}
# This is a url where the most recent plugin package can be downloaded.
__url__ = 'https://github.com/oddluck/limnoria-plugins/'
from . import config
from . import plugin
from imp import reload
# In case we're being reloaded.
reload(config)
reload(plugin)
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!
if world.testing:
from . import test
Class = plugin.Class
configure = config.configure
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

58
MLBScores/config.py Normal file
View File

@ -0,0 +1,58 @@
###
# Copyright (c) 2018, cottongin
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
import supybot.conf as conf
import supybot.registry as registry
try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('MLBScores')
except:
# Placeholder that allows to run the plugin on a bot
# without the i18n module
_ = lambda x: x
def configure(advanced):
# This will be called by supybot to configure this module. advanced is
# a bool that specifies whether the user identified themself as an advanced
# user or not. You should effect your configuration by manipulating the
# registry as appropriate.
from supybot.questions import expect, anything, something, yn
conf.registerPlugin('MLBScores', True)
MLBScores = conf.registerPlugin('MLBScores')
# This is where your configuration variables (if any) should go. For example:
# conf.registerGlobalValue(MLBScores, 'someConfigVariableName',
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
conf.registerGlobalValue(MLBScores, 'bitlyAPIKey',
registry.String('', """Bit.ly API key.""", private=True))
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

109
MLBScores/inputParser.py Normal file
View File

@ -0,0 +1,109 @@
import pendulum
import re
_FUZZY_DAYS = ['yesterday', 'tonight', 'today', 'tomorrow',
'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
def _parseDate(string):
"""parse date"""
date = string[:3].lower()
if date in _FUZZY_DAYS or string.lower() in _FUZZY_DAYS:
if date == 'yes':
date_string = pendulum.yesterday('US/Pacific').format('YYYY-MM-DD')
#print(date_string)
return date_string
elif date == 'tod' or date == 'ton':
date_string = pendulum.now('US/Pacific').format('YYYY-MM-DD')
return date_string
elif date == 'tom':
date_string = pendulum.tomorrow('US/Pacific').format('YYYY-MM-DD')
return date_string
elif date == 'sun':
date_string = pendulum.now('US/Pacific').next(pendulum.SUNDAY).format('YYYY-MM-DD')
return date_string
elif date == 'mon':
date_string = pendulum.now('US/Pacific').next(pendulum.MONDAY).format('YYYY-MM-DD')
return date_string
elif date == 'tue':
date_string = pendulum.now('US/Pacific').next(pendulum.TUESDAY).format('YYYY-MM-DD')
return date_string
elif date == 'wed':
date_string = pendulum.now('US/Pacific').next(pendulum.WEDNESDAY).format('YYYY-MM-DD')
return date_string
elif date == 'thu':
date_string = pendulum.now('US/Pacific').next(pendulum.THURSDAY).format('YYYY-MM-DD')
return date_string
elif date == 'fri':
date_string = pendulum.now('US/Pacific').next(pendulum.FRIDAY).format('YYYY-MM-DD')
return date_string
elif date == 'sat':
date_string = pendulum.now('US/Pacific').next(pendulum.SATURDAY).format('YYYY-MM-DD')
return date_string
def parseInput(args=None, _TEAM_BY_TRI=None, _TEAM_BY_NICK=None):
"""parse user input from mlb2"""
# return team, date, timezone
tz = 'US/Eastern'
date = None
team = None
is_date = None
if not args:
return team, date, tz
arg_array = []
for arg in args.split(' '):
arg_array.append(arg)
print(_TEAM_BY_TRI)
for idx, arg in enumerate(arg_array):
#print(arg)
if '--tz' in arg:
#print(arg_array[idx+1])
try:
tz = arg_array[idx+1]
except:
tz = 'US/Eastern'
if arg.lower() in _FUZZY_DAYS or arg[:3].lower() in _FUZZY_DAYS:
date = _parseDate(arg)
#print(date)
#date = pendulum.parse(date).in_tz(tz)
try:
arg = arg.strip('-')
arg = arg.strip('/')
if arg[0].isdigit() and arg[1].isdigit() and arg[2].isalpha():
if arg[-1].isdigit():
yr = arg[-2:]
mnth = " ".join(re.findall("[a-zA-Z]+", arg))
#print(mnth,yr)
rebuild = '{}-{}-{}'.format(mnth, arg[:2], yr)
else:
rebuild = arg[2:] + arg[:2]
#print('both', rebuild)
elif arg[0].isdigit() and arg[1].isalpha():
rebuild = arg[1:] + arg[0]
#print('one', rebuild)
else:
rebuild = arg
#print(rebuild)
is_date = pendulum.parse(rebuild, strict=False)
#print(is_date)
except:
is_date = None
if is_date:
date = is_date.format('YYYY-MM-DD')
if _TEAM_BY_TRI and _TEAM_BY_NICK:
if arg.upper() in _TEAM_BY_TRI:
team = str(_TEAM_BY_TRI[arg.upper()])
elif arg.lower() in _TEAM_BY_NICK:
abbr = str(_TEAM_BY_NICK[arg.lower()])
team = str(_TEAM_BY_TRI[abbr])
#else:
# team = arg.upper()
print(team)
return team, date, tz

4049
MLBScores/plugin.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,6 @@
requests==2.18.1
httplib2==0.11.3
limnoria==2018.6.25
pytz==2014.10
python_dateutil==2.7.3
pendulum==2.0.3

38
MLBScores/test.py Normal file
View File

@ -0,0 +1,38 @@
###
# Copyright (c) 2018, cottongin
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from supybot.test import *
class MLBScoresTestCase(PluginTestCase):
plugins = ('MLBScores',)
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: