Skip to content

Commit

Permalink
Merge branch 'master' into cloud-eval-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MxHonesty authored Oct 13, 2020
2 parents 60f9e4c + b833d2f commit de7b195
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 python-chess
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# - name: Lint with flake8
# run: |
# # stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings
# flake8 . --count --exit-zero --ignore=E203,E501,W503 --max-complexity=10 --statistics
# - name: Check formatting with black
# run: |
# black . --check
- name: Test
run: |
python test.py
21 changes: 5 additions & 16 deletions lichess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ def user(username, **kwargs):
return _api_get('/api/user/{}'.format(username), kwargs)

def users_by_team(team, **kwargs):
"""Wrapper for the `GET /api/user <https://github.com/ornicar/lila#get-apiuser-fetch-many-users-from-a-team>`_ endpoint.
"""Wrapper for the `GET /api/team/{name}/users <https://github.com/ornicar/lila#get-apiuser-fetch-many-users-from-a-team>`_ endpoint.
Returns a generator that streams the user data.
>>> users = lichess.api.users_by_team('coders')
>>> ratings = [u.get('perfs', {}).get('blitz', {}).get('rating') for u in users]
>>> print(ratings)
[1349, 1609, ...]
"""
return _api_get('/team/{}/users'.format(team), kwargs, object_type=lichess.format.STREAM_OBJECT)
return _api_get('/api/team/{}/users'.format(team), kwargs, object_type=lichess.format.STREAM_OBJECT)

def users_by_ids(ids, **kwargs):
"""Wrapper for the `POST /api/users <https://github.com/ornicar/lila#post-apiusers-fetch-many-users-by-id>`_ endpoint.
Expand Down Expand Up @@ -236,15 +236,15 @@ def game(game_id, **kwargs):
return _api_get('/game/export/{}'.format(game_id), kwargs, object_type=lichess.format.GAME_OBJECT)

def games_by_ids(ids, **kwargs):
"""Wrapper for the `POST /api/games <https://github.com/ornicar/lila#post-apigames-fetch-many-games-by-id>`_ endpoint.
"""Wrapper for the `POST /games/export/_ids <https://github.com/ornicar/lila#post-apigames-fetch-many-games-by-id>`_ endpoint.
Returns a generator that splits the IDs into multiple requests as needed."""
return _batch(games_by_ids_page, [ids], kwargs, 300)

def games_by_ids_page(ids, **kwargs):
"""Wrapper for the `POST /api/games <https://github.com/ornicar/lila#post-apigames-fetch-many-games-by-id>`_ endpoint.
"""Wrapper for the `POST /games/export/_ids <https://github.com/ornicar/lila#post-apigames-fetch-many-games-by-id>`_ endpoint.
Use :data:`~lichess.api.games_by_ids` to avoid manual pagination.
"""
return _api_post('/api/games', kwargs, ','.join(ids))
return _api_post('/games/export/_ids', kwargs, ','.join(ids), object_type=lichess.format.GAME_STREAM_OBJECT)

def user_games(username, **kwargs):
"""Wrapper for the `GET /api/user/<username>/games <https://github.com/ornicar/lila#get-apiuserusernamegames-fetch-user-games>`_ endpoint.
Expand Down Expand Up @@ -286,17 +286,6 @@ def current_game(username, **kwargs):
Returns a single game."""
return _api_get('/api/user/{}/current-game'.format(username), kwargs, object_type=lichess.format.GAME_OBJECT)

def games_by_team(team, **kwargs):
"""Wrapper for the `GET /api/games/team/<teamId> <https://github.com/ornicar/lila#get-apigamesteamteamid-fetch-games-between-players-of-a-team>`_ endpoint.
Returns a generator that makes requests for additional pages as needed."""
return _enum(games_by_team_page, [team], kwargs)

def games_by_team_page(team, **kwargs):
"""Wrapper for the `GET /api/games/team/<teamId> <https://github.com/ornicar/lila#get-apigamesteamteamid-fetch-games-between-players-of-a-team>`_ endpoint.
Use :data:`~lichess.api.games_by_team` to avoid manual pagination.
"""
return _api_get('/api/games/team/{}'.format(team), kwargs)

def tournaments(**kwargs):
"""Wrapper for the `GET /api/tournament <https://github.com/ornicar/lila#get-apitournament-fetch-current-tournaments>`_ endpoint."""
return _api_get('/api/tournament', kwargs)
Expand Down
8 changes: 3 additions & 5 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def test_user_games(self):
moves2 = lst[1]['moves']
self.assertEqual(type(moves1), type(u''))
self.assertEqual(type(moves2), type(u''))
self.assertNotEqual(moves1, moves2)

def test_user_games_pgn(self):
pgns = lichess.api.user_games('thibault', max=5, format=lichess.format.PGN)
Expand Down Expand Up @@ -130,10 +129,9 @@ def test_pychess(self):
fen = game.end().board().fen()
self.assertEqual(fen, '2k1Rbr1/1ppr1Np1/p6p/8/3p4/P2P3P/1PP2PP1/2KR4 b - - 2 19')

def test_pgn_from_game(self):
api_game = lichess.api.game('9PzeRgcM', with_moves=1)
pgn = lichess.pgn.io_from_game(api_game)
game = chess.pgn.read_game(pgn)
def test_pychess_correspondence(self):
api_game = lichess.api.game('9PzeRgcM')
game = chess.pgn.read_game(lichess.pgn.io_from_game(api_game))
fen = game.end().board().fen()
self.assertEqual(fen, '2r5/p2Q1ppp/1p2k3/1Bb1P3/5B2/P7/1P3PPP/R3K2R b KQ - 0 21')

Expand Down

0 comments on commit de7b195

Please sign in to comment.