Mohamed Essam commited on
Commit
2d755fd
·
1 Parent(s): 7bb1371

DEV: type checking

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -7,7 +7,7 @@ from datetime import datetime
7
  from typing import Dict, Literal, Union
8
 
9
 
10
- def get_matches_by_date(date: datetime) -> Dict[Union[Literal["id"], Literal["error"]],
11
  Union[str,Dict[Literal["competition", "home_team", "away_team", "home_score", "away_score"], str]]]:
12
 
13
  """
@@ -20,7 +20,10 @@ def get_matches_by_date(date: datetime) -> Dict[Union[Literal["id"], Literal["er
20
  dict: A dictionary with the match ID as the key, and a dictionary containing the competition, home team, away team, home score and away score as the value
21
  """
22
 
23
- date_formatted = date.strftime("%Y-%m-%d")
 
 
 
24
 
25
  api_key = os.getenv("FOOTBALL_DATA_API_KEY")
26
 
@@ -63,7 +66,13 @@ def get_matches_by_date(date: datetime) -> Dict[Union[Literal["id"], Literal["er
63
  demo = gr.Interface(
64
  get_matches_by_date,
65
  inputs=[
66
- gr.DateTime(value=datetime.now(), type="datetime", include_time=False, label="Matches on this date"),
 
 
 
 
 
 
67
  ],
68
  outputs=[
69
  gr.JSON(),
 
7
  from typing import Dict, Literal, Union
8
 
9
 
10
+ def get_matches_by_date(date: float | datetime | str | None) -> Dict[Union[Literal["id"], Literal["error"]],
11
  Union[str,Dict[Literal["competition", "home_team", "away_team", "home_score", "away_score"], str]]]:
12
 
13
  """
 
20
  dict: A dictionary with the match ID as the key, and a dictionary containing the competition, home team, away team, home score and away score as the value
21
  """
22
 
23
+ if date is None:
24
+ date = datetime.now()
25
+
26
+ date_formatted = date.strftime("%Y-%m-%d") if isinstance(date, datetime) else date
27
 
28
  api_key = os.getenv("FOOTBALL_DATA_API_KEY")
29
 
 
66
  demo = gr.Interface(
67
  get_matches_by_date,
68
  inputs=[
69
+ gr.DateTime(
70
+ value=datetime.now(),
71
+ type="datetime",
72
+ include_time=False,
73
+ label="Matches on this date",
74
+ interactive=True
75
+ )
76
  ],
77
  outputs=[
78
  gr.JSON(),