├── ff_bot ├── __init__.py ├── tests │ ├── __init__.py │ └── test_groupmebot.py └── ff_bot.py ├── .gitignore ├── setup.cfg ├── Dockerfile ├── .travis.yml ├── setup.py └── README.md /ff_bot/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /ff_bot/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:latest 2 | 3 | # Install app 4 | ADD . /usr/src/ff_bot 5 | WORKDIR /usr/src/ff_bot 6 | RUN python3 setup.py install 7 | 8 | # Launch app 9 | CMD ["python3", "ff_bot/ff_bot.py"] -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | language: python 4 | python: 5 | - "3.3" 6 | - "3.4" 7 | - "3.5" 8 | 9 | services: 10 | - docker 11 | 12 | install: 13 | - docker build -t test_build . 14 | - docker run test_build python3 /usr/src/ff_bot/setup.py test 15 | 16 | before_script: 17 | - pip3 install flake8 18 | 19 | script: 20 | - docker ps -a | grep test_build 21 | - flake8 . 22 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup( 4 | name='ff_bot', 5 | 6 | packages=['ff_bot'], 7 | 8 | include_package_data=True, 9 | 10 | version='0.0.1', 11 | 12 | description='ESPN fantasy football GroupMe Bot', 13 | 14 | author='Rich Barton', 15 | 16 | author_email='rbart65@gmail.com', 17 | 18 | install_requires=['requests>=2.0.0,<3.0.0', 'espnff>=1.2.1,<3.0.0'], 19 | 20 | test_suite='nose.collector', 21 | 22 | tests_require=['nose', 'requests_mock'], 23 | 24 | url='https://github.com/rbarton65/ff_bot', 25 | 26 | classifiers=[ 27 | 'Natural Language :: English', 28 | 'Operating System :: OS Independent', 29 | 'License :: OSI Approved :: BSD License', 30 | 'Programming Language :: Python :: 3', 31 | 'Topic :: Software Development :: Libraries :: Python Modules', 32 | ] 33 | ) 34 | -------------------------------------------------------------------------------- /ff_bot/tests/test_groupmebot.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | import requests_mock 5 | 6 | 7 | from ff_bot.ff_bot import (GroupMeBot, GroupMeException, ) 8 | 9 | 10 | class GroupMeBotTestCase(unittest.TestCase): 11 | '''Test GroupMeBot class''' 12 | 13 | def setUp(self): 14 | self.test_bot = GroupMeBot("123456") 15 | self.test_text = "This is a test." 16 | 17 | @requests_mock.Mocker() 18 | def test_send_message(self, m): 19 | '''Does the message send successfully?''' 20 | m.post("https://api.groupme.com/v3/bots/post", status_code=202) 21 | self.assertEqual(self.test_bot.send_message(self.test_text).status_code, 202) 22 | 23 | @requests_mock.Mocker() 24 | def test_bad_bot_id(self, m): 25 | '''Does the expected error raise when a bot id is incorrect?''' 26 | m.post("https://api.groupme.com/v3/bots/post", status_code=404) 27 | with self.assertRaises(GroupMeException): 28 | self.test_bot.send_message(self.test_text) 29 | -------------------------------------------------------------------------------- /ff_bot/ff_bot.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import os 4 | 5 | from espnff import League 6 | 7 | 8 | class GroupMeException(Exception): 9 | pass 10 | 11 | 12 | class GroupMeBot(object): 13 | '''Creates GroupMe Bot to send messages''' 14 | def __init__(self, bot_id): 15 | self.bot_id = bot_id 16 | 17 | def __repr__(self): 18 | return "GroupMeBot(%s)" % self.bot_id 19 | 20 | def send_message(self, text): 21 | '''Sends a message to the chatroom''' 22 | template = { 23 | "bot_id": self.bot_id, 24 | "text": text, 25 | "attachments": [] 26 | } 27 | 28 | headers = {'content-type': 'application/json'} 29 | r = requests.post("https://api.groupme.com/v3/bots/post", 30 | data=json.dumps(template), headers=headers) 31 | if r.status_code != 202: 32 | raise GroupMeException('Invalid BOT_ID') 33 | 34 | return r 35 | 36 | 37 | def get_scoreboard(league_id, year): 38 | '''Gets current week's scoreboard''' 39 | league = League(league_id, year) 40 | matchups = league.scoreboard() 41 | score = ['%s %s - %s %s' % (i.home_team.team_abbrev, i.home_score, 42 | i.away_score, i.away_team.team_abbrev) for i in matchups 43 | if i.away_team] 44 | text = ['Score Update'] + score 45 | return '\n'.join(text) 46 | 47 | 48 | def main(): 49 | bot_id = os.environ["BOT_ID"] 50 | league_id = os.environ["LEAGUE_ID"] 51 | year = os.environ["LEAGUE_YEAR"] 52 | bot = GroupMeBot(bot_id) 53 | text = get_scoreboard(league_id, year) 54 | bot.send_message(text) 55 | 56 | 57 | if __name__ == '__main__': 58 | main() 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/rbarton65/ff_bot.svg?branch=master)](https://travis-ci.org/rbarton65/ff_bot) 2 | 3 | # ESPN Fantasy Football GroupMe Bot 4 | 5 | This package creates a docker container that runs a GroupMe chat bot to send 6 | ESPN Fantasy Football information to a GroupMe chat room. 7 | 8 | ## Getting Started 9 | 10 | These instructions will get you a copy of the project up and running 11 | on your local machine for development and testing purposes. 12 | 13 | ### Installing 14 | With Docker: 15 | ```bash 16 | git clone https://github.com/rbarton65/ff_bot 17 | 18 | cd ff_bot 19 | 20 | docker build -t ff_bot . 21 | ``` 22 | 23 | Without Docker: 24 | 25 | ```bash 26 | git clone https://github.com/rbarton65/ff_bot 27 | 28 | cd ff_bot 29 | 30 | python3 setup.py install 31 | ``` 32 | 33 | 34 | ## Basic Usage 35 | 36 | This gives an overview of all the features of `ff_bot` 37 | 38 | ### Running with Docker 39 | 40 | ```bash 41 | >>> export BOT_ID=[enter your GroupMe Bot ID] 42 | >>> export LEAGUE_ID=[enter ESPN league ID] 43 | >>> export LEAGUE_YEAR=[enter league year] 44 | >>> cd ff_bot 45 | >>> docker run --rm=True \ 46 | -e BOT_ID=$BOT_ID \ 47 | -e LEAGUE_ID=$LEAGUE_ID \ 48 | -e LEAGUE_YEAR=$LEAGUE_YEAR \ 49 | ff_bot 50 | ``` 51 | 52 | ### Running without Docker 53 | 54 | ```bash 55 | >>> export BOT_ID=[enter your GroupMe Bot ID] 56 | >>> export LEAGUE_ID=[enter ESPN league ID] 57 | >>> export LEAGUE_YEAR=[enter league year] 58 | >>> cd ff_bot 59 | >>> python3 ff_bot/ff_bot.py 60 | ``` 61 | 62 | ## Running the tests 63 | 64 | Automated tests for this package are included in the `tests` directory. After installation, 65 | you can run these tests by changing the directory to the `ff_bot` directory and running the following: 66 | 67 | ```python3 68 | python3 setup.py test 69 | ``` --------------------------------------------------------------------------------