Spaces:
Sleeping
Sleeping
Update app.py
Browse filesI've switched to a currently active public API: https://gagstock.gleeze.com/grow-a-garden
This provides fresh real-time stock (including seeds) with low latency, and it's free/public.
app.py
CHANGED
|
@@ -2,18 +2,24 @@ import requests
|
|
| 2 |
import gradio as gr
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
def fetch_stock():
|
| 8 |
try:
|
| 9 |
-
response = requests.get(API_URL, timeout=
|
| 10 |
response.raise_for_status()
|
| 11 |
data = response.json()
|
| 12 |
-
if
|
| 13 |
-
return {"error": "
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
except Exception as e:
|
| 16 |
-
return {"error": f"API error: {str(e)}.
|
| 17 |
|
| 18 |
def check_seeds(desired_seeds):
|
| 19 |
stock_data = fetch_stock()
|
|
@@ -42,7 +48,7 @@ with gr.Blocks(title="Grow A Garden Seed Notifier 🌱", js="""
|
|
| 42 |
() => {
|
| 43 |
setInterval(() => {
|
| 44 |
document.querySelector('button#refresh_button').click();
|
| 45 |
-
}, 60000); // Auto-refresh every 60 seconds
|
| 46 |
}
|
| 47 |
""") as demo:
|
| 48 |
gr.Markdown("# Grow A Garden Seed Notifier 🌱")
|
|
@@ -59,7 +65,6 @@ with gr.Blocks(title="Grow A Garden Seed Notifier 🌱", js="""
|
|
| 59 |
|
| 60 |
refresh_button = gr.Button("Manual Refresh Now", elem_id="refresh_button")
|
| 61 |
|
| 62 |
-
# Button click and initial load both update the display
|
| 63 |
refresh_button.click(
|
| 64 |
fn=check_seeds,
|
| 65 |
inputs=desired_input,
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
+
# Reliable public API (when active; community-hosted)
|
| 6 |
+
API_URL = "https://gagstock.gleeze.com/grow-a-garden"
|
| 7 |
|
| 8 |
def fetch_stock():
|
| 9 |
try:
|
| 10 |
+
response = requests.get(API_URL, timeout=15)
|
| 11 |
response.raise_for_status()
|
| 12 |
data = response.json()
|
| 13 |
+
if data.get("status") != "success":
|
| 14 |
+
return {"error": "API returned non-success status."}
|
| 15 |
+
seeds_data = data.get("data", {}).get("seed", {}).get("items", [])
|
| 16 |
+
if not seeds_data:
|
| 17 |
+
return {"error": "No seed data found in API response."}
|
| 18 |
+
return seeds_data
|
| 19 |
+
except requests.exceptions.ConnectionError:
|
| 20 |
+
return {"error": "Cannot connect to API (server down). Use live trackers like growagardenstock.org or growagardenpro.com."}
|
| 21 |
except Exception as e:
|
| 22 |
+
return {"error": f"API error: {str(e)}. Check growagardenstock.org or vulcanvalues.com/grow-a-garden/stock for live data."}
|
| 23 |
|
| 24 |
def check_seeds(desired_seeds):
|
| 25 |
stock_data = fetch_stock()
|
|
|
|
| 48 |
() => {
|
| 49 |
setInterval(() => {
|
| 50 |
document.querySelector('button#refresh_button').click();
|
| 51 |
+
}, 60000); // Auto-refresh every 60 seconds
|
| 52 |
}
|
| 53 |
""") as demo:
|
| 54 |
gr.Markdown("# Grow A Garden Seed Notifier 🌱")
|
|
|
|
| 65 |
|
| 66 |
refresh_button = gr.Button("Manual Refresh Now", elem_id="refresh_button")
|
| 67 |
|
|
|
|
| 68 |
refresh_button.click(
|
| 69 |
fn=check_seeds,
|
| 70 |
inputs=desired_input,
|