hkjc 0.3.22__py3-none-any.whl → 0.3.23__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hkjc/historical.py CHANGED
@@ -25,6 +25,7 @@ HTML_HEADERS = {
25
25
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36",
26
26
  }
27
27
 
28
+
28
29
  @ttl_cache(maxsize=100, ttl=3600)
29
30
  def _soupify(url: str) -> BeautifulSoup:
30
31
  """Fetch and parse a webpage and return BeautifulSoup object
@@ -54,7 +55,7 @@ def _classify_running_style(df: pl.DataFrame, running_pos_col="RunningPosition")
54
55
  """
55
56
  if df.height == 0:
56
57
  return df
57
-
58
+
58
59
  # Split the RunningPosition column into separate columns and convert to integers
59
60
  df = df.with_columns(
60
61
  pl.col(running_pos_col)
@@ -86,12 +87,16 @@ def _extract_horse_data(horse_no: str) -> pl.DataFrame:
86
87
  """Extract horse info and history from horse page
87
88
  """
88
89
  soup = _soupify_horse_page(horse_no)
90
+ horse_name = soup.find('title').get_text().split('- Horses -')[0].strip()
89
91
  table = soup.find('table', class_='bigborder')
90
92
  horse_data = _parse_html_table(table).filter(
91
93
  pl.col('Date') != '') # Remove empty rows
92
94
  if horse_data.height > 0:
93
95
  horse_data = _classify_running_style(horse_data)
94
- horse_data = horse_data.with_columns(pl.lit(horse_no).alias('HorseNo'))
96
+ horse_data = horse_data.with_columns([
97
+ pl.lit(horse_no).alias('HorseNo'),
98
+ pl.lit(horse_name).alias('HorseName')
99
+ ])
95
100
 
96
101
  return horse_data
97
102
 
@@ -101,7 +106,7 @@ def _clean_horse_data(df: pl.DataFrame) -> pl.DataFrame:
101
106
  """
102
107
  if df.height == 0:
103
108
  return df
104
-
109
+
105
110
  df = df.with_columns(
106
111
  pl.col('Pla').str.split(' ').list.first().alias('Pla')
107
112
  ).filter(~pl.col('Pla').is_in(incidents))
@@ -152,7 +157,7 @@ def _clean_race_data(df: pl.DataFrame) -> pl.DataFrame:
152
157
  """
153
158
  if df.height == 0:
154
159
  return df
155
-
160
+
156
161
  df = df.with_columns(
157
162
  pl.col('Pla').str.split(' ').list.first().alias('Pla')
158
163
  ).filter(~pl.col('Pla').is_in(incidents))
hkjc/live.py CHANGED
@@ -269,7 +269,16 @@ def _fetch_live_races(date: str = None, venue_code: str = None) -> dict:
269
269
  if r.status_code != 200:
270
270
  raise RuntimeError(f"Request failed: {r.status_code} - {r.text}")
271
271
 
272
- data = r.json()['data']['raceMeetings'][0]
272
+ data = r.json()['data']['raceMeetings'] # list of all meetings
273
+
274
+ # Prioritize first local race, if not continue with the first race (default 0)
275
+ index = 0
276
+ for i, entry in enumerate(data):
277
+ if entry['venueCode'] in ['HV', 'ST']:
278
+ index = i
279
+ break
280
+
281
+ data = data[index]
273
282
  races = data['races']
274
283
 
275
284
  race_info = {'Date': data['date'], 'Venue': data['venueCode'], 'Races': {}}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hkjc
3
- Version: 0.3.22
3
+ Version: 0.3.23
4
4
  Summary: Library for scrapping HKJC data and perform basic analysis
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: beautifulsoup4>=4.14.2
@@ -12,5 +12,4 @@ Requires-Dist: numpy>=2.3.3
12
12
  Requires-Dist: polars>=1.33.1
13
13
  Requires-Dist: pyarrow>=21.0.0
14
14
  Requires-Dist: requests>=2.32.5
15
- Requires-Dist: scipy>=1.16.2
16
15
  Requires-Dist: tqdm>=4.67.1
@@ -1,14 +1,14 @@
1
1
  hkjc/__init__.py,sha256=XSm9N6YbZ2SzyxjO9aR26ctB4Z1-VeBImuroSgncUfk,737
2
2
  hkjc/features.py,sha256=LicwtKBpMzpz_dSX9bjoCLLaRUu8oeZo1AloTe7v7sI,298
3
3
  hkjc/harville_model.py,sha256=WSA_1EcNOHKGraP6WVHJ3FXZPGrDrjKhJc_q70KKx80,20188
4
- hkjc/historical.py,sha256=22qpMFI7IQ5bfXuGma5jJAtx8chRp4FE-XCIF4RqwTo,8238
5
- hkjc/live.py,sha256=YZgwSLDFq5v1yxNwjTtQxgU2ru4yvooxpjHksDar1TA,10691
4
+ hkjc/historical.py,sha256=88z3DiWuj1L0sJw5EXnEkg4L_xx7-UH6UI6x9duDMvI,8380
5
+ hkjc/live.py,sha256=DgCjqd-QHdUk2ReSQoxIcUhcChCqtUG60p8r-iHnk-k,10958
6
6
  hkjc/processing.py,sha256=hQnHxl6HYlFOeSLSOCVsemgTKcwt9_tYUQI-itpvjUg,7188
7
7
  hkjc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  hkjc/speedpro.py,sha256=Y2Z3GYGeePc4sM-ZnCHXCI1N7L-_j9nrMqS3CC5BBSo,2031
9
9
  hkjc/utils.py,sha256=uAiFmy5NXsADUiD1-MCPgs1hs4N3e7tVYtSREkxwKSQ,6425
10
10
  hkjc/strategy/place_only.py,sha256=lHPjTSj8PzghxncNBg8FI4T4HJigekB9a3bV7l7VtPA,2079
11
11
  hkjc/strategy/qpbanker.py,sha256=MQxjwsfhllKZroKS8w8Q3bi3HMjGc1DAyBIjNZAp3yQ,4805
12
- hkjc-0.3.22.dist-info/METADATA,sha256=gM8crCYg0Wq-W8GFa0Jyk6RYdT-3MUXrAXpl6ID7VcM,480
13
- hkjc-0.3.22.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- hkjc-0.3.22.dist-info/RECORD,,
12
+ hkjc-0.3.23.dist-info/METADATA,sha256=_BEaF2r7sXrq2lhdFj-qunHEKL4koB8-vJtbDs0ZeVw,451
13
+ hkjc-0.3.23.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ hkjc-0.3.23.dist-info/RECORD,,
File without changes