Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,51 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
-
demo.launch()
|
|
|
|
| 1 |
+
# 4D Jackpot Project - Initial Scraper Skeleton
|
| 2 |
+
# Target operators: Sports Toto, Magnum 4D, Da Ma Cai
|
| 3 |
+
# Goal: Extract past 10 years draw results for dataset building
|
| 4 |
|
| 5 |
+
import requests
|
| 6 |
+
from bs4 import BeautifulSoup
|
| 7 |
+
import pandas as pd
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def scrape_sportstoto(year: int):
|
| 12 |
+
"""
|
| 13 |
+
Scrape Sports Toto 4D results for a given year.
|
| 14 |
+
(Placeholder - actual site structure to be inspected)
|
| 15 |
+
"""
|
| 16 |
+
url = f"https://www.sportstoto.com.my/4d-results/{year}"
|
| 17 |
+
response = requests.get(url)
|
| 18 |
+
if response.status_code != 200:
|
| 19 |
+
print(f"❌ Failed to fetch {url}")
|
| 20 |
+
return []
|
| 21 |
+
|
| 22 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 23 |
+
draws = []
|
| 24 |
+
|
| 25 |
+
# TODO: Inspect actual page structure and update selectors
|
| 26 |
+
for row in soup.select(".resultRow"):
|
| 27 |
+
date_str = row.select_one(".date").text.strip()
|
| 28 |
+
draw_date = datetime.strptime(date_str, "%d/%m/%Y")
|
| 29 |
+
numbers = [n.text.strip() for n in row.select(".number")]
|
| 30 |
+
draws.append({
|
| 31 |
+
"operator": "Sports Toto",
|
| 32 |
+
"date": draw_date,
|
| 33 |
+
"numbers": numbers
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
return draws
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def save_results(all_results, filename="4d_history.csv"):
|
| 40 |
+
df = pd.DataFrame(all_results)
|
| 41 |
+
df.to_csv(filename, index=False)
|
| 42 |
+
print(f"✅ Saved {len(df)} draws to {filename}")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
results = []
|
| 47 |
+
for year in range(2015, 2025): # Past 10 years
|
| 48 |
+
results.extend(scrape_sportstoto(year))
|
| 49 |
+
|
| 50 |
+
save_results(results)
|
| 51 |
|
|
|
|
|
|