Spaces:
Sleeping
Sleeping
Update primitives/tools.py
Browse files- primitives/tools.py +7 -8
primitives/tools.py
CHANGED
|
@@ -63,8 +63,7 @@ TYPE_MAPPING = {
|
|
| 63 |
# Available tools
|
| 64 |
# -----------------
|
| 65 |
|
| 66 |
-
async def cricket_source(
|
| 67 |
-
mode: Literal["live", "upcomming"], want: Literal["text", "herf"] ) -> str:
|
| 68 |
"""Fetches whole html from source extracts html container that contains necessary details
|
| 69 |
|
| 70 |
Args:
|
|
@@ -74,7 +73,7 @@ async def cricket_source(
|
|
| 74 |
|
| 75 |
if mode == "live":
|
| 76 |
url = f"{BASE_CRICKET_URL}/cricket-match/live-scores"
|
| 77 |
-
elif mode == '
|
| 78 |
url = f"{BASE_CRICKET_URL}/cricket-match/live-scores/upcoming-matches"
|
| 79 |
else:
|
| 80 |
error = f"Not Implemented: Currently there's no implementation to handle {mode}. Only handels live, upcomming"
|
|
@@ -95,7 +94,7 @@ async def cricket_source(
|
|
| 95 |
|
| 96 |
# find where the content is
|
| 97 |
container = html.find("div", class_= 'cb-col cb-col-100 cb-rank-tabs')
|
| 98 |
-
if mode in ['live', '
|
| 99 |
text = container.get_text(separator=" ", strip= True)
|
| 100 |
return json.dumps({f"{mode} details": str(text)})
|
| 101 |
elif mode == 'live' and want == 'herf':
|
|
@@ -109,18 +108,18 @@ async def cricket_source(
|
|
| 109 |
return json.dumps({"error": "No Available details right now!"})
|
| 110 |
|
| 111 |
|
| 112 |
-
async def fetch_cricket_details(mode: Literal["live", "
|
| 113 |
-
"""Get cricket Live or
|
| 114 |
|
| 115 |
Args:
|
| 116 |
-
mode : Either "live" or "
|
| 117 |
"""
|
| 118 |
response = await cricket_source(mode.strip().lower(), want= 'text')
|
| 119 |
return response
|
| 120 |
|
| 121 |
|
| 122 |
async def live_cricket_scorecard_herf()-> str:
|
| 123 |
-
"""String of comma separated anchor tags with
|
| 124 |
response = await cricket_source('live', 'herf')
|
| 125 |
return response
|
| 126 |
|
|
|
|
| 63 |
# Available tools
|
| 64 |
# -----------------
|
| 65 |
|
| 66 |
+
async def cricket_source(mode: Literal["live", "upcoming"], want: Literal["text", "href"] ) -> str:
|
|
|
|
| 67 |
"""Fetches whole html from source extracts html container that contains necessary details
|
| 68 |
|
| 69 |
Args:
|
|
|
|
| 73 |
|
| 74 |
if mode == "live":
|
| 75 |
url = f"{BASE_CRICKET_URL}/cricket-match/live-scores"
|
| 76 |
+
elif mode == 'upcoming':
|
| 77 |
url = f"{BASE_CRICKET_URL}/cricket-match/live-scores/upcoming-matches"
|
| 78 |
else:
|
| 79 |
error = f"Not Implemented: Currently there's no implementation to handle {mode}. Only handels live, upcomming"
|
|
|
|
| 94 |
|
| 95 |
# find where the content is
|
| 96 |
container = html.find("div", class_= 'cb-col cb-col-100 cb-rank-tabs')
|
| 97 |
+
if mode in ['live', 'upcoming'] and want == "text":
|
| 98 |
text = container.get_text(separator=" ", strip= True)
|
| 99 |
return json.dumps({f"{mode} details": str(text)})
|
| 100 |
elif mode == 'live' and want == 'herf':
|
|
|
|
| 108 |
return json.dumps({"error": "No Available details right now!"})
|
| 109 |
|
| 110 |
|
| 111 |
+
async def fetch_cricket_details(mode: Literal["live", "upcoming"])-> str:
|
| 112 |
+
"""Get cricket Live or Upcoming match details
|
| 113 |
|
| 114 |
Args:
|
| 115 |
+
mode : Either "live" or "upcoming"
|
| 116 |
"""
|
| 117 |
response = await cricket_source(mode.strip().lower(), want= 'text')
|
| 118 |
return response
|
| 119 |
|
| 120 |
|
| 121 |
async def live_cricket_scorecard_herf()-> str:
|
| 122 |
+
"""String of comma separated anchor tags with hreg attributes that pointing to live cricket scorecards """
|
| 123 |
response = await cricket_source('live', 'herf')
|
| 124 |
return response
|
| 125 |
|