Skip to content

Instantly share code, notes, and snippets.

@henriquebastos
Created February 18, 2022 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henriquebastos/659948c339040301d616277b8d328fe2 to your computer and use it in GitHub Desktop.
Save henriquebastos/659948c339040301d616277b8d328fe2 to your computer and use it in GitHub Desktop.
Code Review do Betapp
diff --git a/betapp/betapp/greyhound/utils/racingpost.py b/betapp/betapp/greyhound/utils/racingpost.py
index db9da89..4f976f1 100644
--- a/betapp/betapp/greyhound/utils/racingpost.py
+++ b/betapp/betapp/greyhound/utils/racingpost.py
@@ -4,7 +4,7 @@ import requests
from dataclasses import dataclass
from dateutil import tz
-from typing import List
+from typing import List, get_type_hints
@dataclass
@@ -22,10 +22,15 @@ class Track:
country: str
races: List[Race]
+class Forecast(float):
+ pass
+
+assert Forecast("5/2") == 2.5
+
@dataclass
class Info:
- forecast: float
+ forecast: Forecast
top_speed: str
best_real_time: str
@@ -51,14 +56,17 @@ def to_datetime(date, mask='%Y-%m-%d %H:%M'):
def deserializer_tracks_with_races(data):
+ data = data['list']['items']
extracted_data = []
for track_data in data:
track = Track(id=int(track_data['track_id']),
name=track_data['track'],
country=track_data['races'][0]['country'],
races=[])
+
+ hints = get_type_hints(Race)
for race_data in track_data['races']:
- race = Race(id=int(race_data['raceId']),
+ race = Race(id=hints["id"](race_data['raceId']),
distance=int(re.findall(r'\d+', race_data['distance'])[0]),
grade=race_data['raceGrade'],
date=to_datetime(race_data['raceDate']))
@@ -104,10 +112,7 @@ class RacingPostClient:
}
data = self.request(path, params)
-
- items_data = data['list']['items']
-
- return deserializer_tracks_with_races(items_data)
+ return deserializer_tracks_with_races(data)
def get_dogs_in_race(self, id, date):
path = '/card/blocks.sd'
diff --git a/betapp/betapp/greyhound/utils/test_racingpost.py b/betapp/betapp/greyhound/utils/test_racingpost.py
index bdccc31..3a748df 100644
--- a/betapp/betapp/greyhound/utils/test_racingpost.py
+++ b/betapp/betapp/greyhound/utils/test_racingpost.py
@@ -9,13 +9,13 @@ from racingpost import RacingPostClient
BASE_DIR = Path(__file__).parent
+RACING_DAY = datetime.date(2021, 2, 15)
@pytest.fixture
def client():
return RacingPostClient()
-@responses.activate
def test_without_tracks(client):
responses.add(
responses.GET,
@@ -23,7 +23,7 @@ def test_without_tracks(client):
json={'list': {'items': []}}, status=200
)
- tracks = client.get_tracks_with_races(datetime.date(2021, 2, 15))
+ tracks = client.get_tracks_with_races(RACING_DAY)
assert tracks == []
@@ -38,5 +38,5 @@ def test_with_tracks(client):
json=json_data, status=200)
- tracks = client.get_tracks_with_races(datetime.date(2021, 2, 15))
+ tracks = client.get_tracks_with_races(RACING_DAY)
assert tracks[0].id == 70
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment