Skip to content

Commit

Permalink
Merge pull request #25 from S1M0N38/dev
Browse files Browse the repository at this point in the history
Refactoring of project structure
  • Loading branch information
S1M0N38 committed Jan 25, 2021
2 parents 18f73c5 + ea81ca9 commit a0a0d57
Show file tree
Hide file tree
Showing 10 changed files with 448 additions and 303 deletions.
22 changes: 21 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -15,21 +15,41 @@ so I can update the documentation.
have to install it on your local machine.

Then clone this Github repository with

```bash
git clone https://github.com/S1M0N38/soccerapi.git
```

and then go into it

```bash
cd soccerapi
```

Then install the dependencies with

```bash
poetry install
```

Finally activate the virtual env with

```bash
poetry shell
```

## Running the test suite

Go into soccerapi directory (the same directory where is README.md) and run
tests with `pipenv run pytest`.
tests with `pytest`.

## Writing Api for new bookmaker

Another way to contribute is to write a Api class for a new bookmaker.
For writing such class take a look at
[example.py](https://github.com/S1M0N38/soccerapi/blob/master/soccerapi/api/example.py)
or at the already implemented Api classes (
[888sport.py](https://github.com/S1M0N38/soccerapi/blob/master/soccerapi/api/888sport.py),
[bet365.py](https://github.com/S1M0N38/soccerapi/blob/master/soccerapi/api/bet365.py),
[unibet.py](https://github.com/S1M0N38/soccerapi/blob/master/soccerapi/api/unibet.py),
).
40 changes: 20 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Expand Up @@ -10,10 +10,10 @@ homepage = "https://github.com/S1M0N38/soccerapi"
[tool.poetry.dependencies]
python = "^3.7"
requests = "^2.25.1"
pytest = "^6.2.1"
pytest-cov = "^2.10.1"

[tool.poetry.dev-dependencies]
pytest = "^6.2.1"
pytest-cov = "^2.10.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
44 changes: 33 additions & 11 deletions soccerapi/api/888sport.py
@@ -1,22 +1,18 @@
import re
from typing import Dict, Tuple

from .base import ApiKambi
import requests

from .base import ApiBase
from .kambi import ParserKambi as Parser888Sport

class Api888Sport(ApiKambi):

class Api888Sport(ApiBase, Parser888Sport):
""" The ApiKambi implementation for 888sport.com """

def __init__(self):
self.name = '888sport'
self.base_url = (
'https://eu-offering.kambicdn.org/'
'offering/v2018/888/listView/football'
)
self.parsers = [
self._full_time_result,
self._both_teams_to_score,
self._double_chance,
]
self.session = requests.Session()

def competition(self, url: str) -> str:
re_888sport = re.compile(
Expand All @@ -28,3 +24,29 @@ def competition(self, url: str) -> str:
else:
msg = f'Cannot parse {url}'
raise ValueError(msg)

def requests(self, competition: str) -> Tuple[Dict]:
return {
'full_time_result': self._request(competition, 12579),
'both_teams_to_score': self._request(competition, 11942),
'double_chance': self._request(competition, 12220),
}

# Auxiliary methods

def _request(
self, competition: str, category: int, market: str = 'IT'
) -> Dict:
""" Make the single request using the active session """

base_url = (
'https://eu-offering.kambicdn.org/'
'offering/v2018/888/listView/football'
)
url = '/'.join([base_url, competition]) + '.json'
params = (
('lang', 'en_US'),
('market', market),
('category', category),
)
return self.session.get(url, params=params).json()
2 changes: 2 additions & 0 deletions soccerapi/api/__init__.py
Expand Up @@ -5,3 +5,5 @@
Api888Sport = importlib.import_module('.888sport', package).Api888Sport
ApiBet365 = importlib.import_module('.bet365', package).ApiBet365
ApiUnibet = importlib.import_module('.unibet', package).ApiUnibet

# ApiExample = importlib.import_module('.example', package).ApiExample

0 comments on commit a0a0d57

Please sign in to comment.