Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
|
|
|
|
| 5 |
def get_epic_free_games():
|
| 6 |
try:
|
| 7 |
url = "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=en-US"
|
|
@@ -18,11 +19,12 @@ def get_epic_free_games():
|
|
| 18 |
slug = game.get("productSlug", "")
|
| 19 |
if slug:
|
| 20 |
link = f"https://store.epicgames.com/p/{slug}"
|
| 21 |
-
results.append(f"
|
| 22 |
return results if results else ["No free games on Epic today."]
|
| 23 |
except Exception as e:
|
| 24 |
-
return [f"Error fetching Epic Games: {e}"]
|
| 25 |
|
|
|
|
| 26 |
def get_steam_games():
|
| 27 |
try:
|
| 28 |
url = "https://isthereanydeal.com/giveaways/"
|
|
@@ -31,6 +33,7 @@ def get_steam_games():
|
|
| 31 |
soup = BeautifulSoup(res.text, "html.parser")
|
| 32 |
game_blocks = soup.find_all("div", class_="giveaway")
|
| 33 |
steam_data = []
|
|
|
|
| 34 |
for block in game_blocks[:5]:
|
| 35 |
title = block.find("div", class_="title").text.strip()
|
| 36 |
link = block.find("a", href=True)["href"]
|
|
@@ -48,30 +51,43 @@ def get_steam_games():
|
|
| 48 |
except Exception as e:
|
| 49 |
return [("https://cdn.cloudflare.steamstatic.com/steam/apps/0/header.jpg", f"Steam error: {e}")]
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
| 58 |
-
# Write to file
|
| 59 |
with open("free_games.txt", "w", encoding="utf-8") as f:
|
| 60 |
-
f.write(
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
return steam_images, summary_text, "free_games.txt"
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
with gr.Blocks() as demo:
|
| 68 |
-
gr.Markdown("
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
-
button
|
|
|
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import requests
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
|
| 5 |
+
# Epic Games
|
| 6 |
def get_epic_free_games():
|
| 7 |
try:
|
| 8 |
url = "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=en-US"
|
|
|
|
| 19 |
slug = game.get("productSlug", "")
|
| 20 |
if slug:
|
| 21 |
link = f"https://store.epicgames.com/p/{slug}"
|
| 22 |
+
results.append(f"๐ฎ {title} (Free {start} to {end}) โ {link}")
|
| 23 |
return results if results else ["No free games on Epic today."]
|
| 24 |
except Exception as e:
|
| 25 |
+
return [f"โ Error fetching Epic Games: {e}"]
|
| 26 |
|
| 27 |
+
# Steam Games + Images
|
| 28 |
def get_steam_games():
|
| 29 |
try:
|
| 30 |
url = "https://isthereanydeal.com/giveaways/"
|
|
|
|
| 33 |
soup = BeautifulSoup(res.text, "html.parser")
|
| 34 |
game_blocks = soup.find_all("div", class_="giveaway")
|
| 35 |
steam_data = []
|
| 36 |
+
|
| 37 |
for block in game_blocks[:5]:
|
| 38 |
title = block.find("div", class_="title").text.strip()
|
| 39 |
link = block.find("a", href=True)["href"]
|
|
|
|
| 51 |
except Exception as e:
|
| 52 |
return [("https://cdn.cloudflare.steamstatic.com/steam/apps/0/header.jpg", f"Steam error: {e}")]
|
| 53 |
|
| 54 |
+
# Combine and Save
|
| 55 |
+
def generate_free_game_data():
|
| 56 |
+
epic = get_epic_free_games()
|
| 57 |
+
steam = get_steam_games()
|
| 58 |
|
| 59 |
+
txt = "๐ฎ Epic Games:\n" + "\n".join(epic) + "\n\n" + \
|
| 60 |
+
"๐ข Steam:\n" + "\n".join([info for _, info in steam])
|
| 61 |
|
|
|
|
| 62 |
with open("free_games.txt", "w", encoding="utf-8") as f:
|
| 63 |
+
f.write(txt)
|
| 64 |
|
| 65 |
+
steam_imgs = [img for img, _ in steam]
|
| 66 |
+
return steam_imgs, txt, "free_games.txt"
|
|
|
|
| 67 |
|
| 68 |
+
# UI with Nice Design
|
| 69 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 70 |
+
gr.Markdown("""
|
| 71 |
+
# ๐น๏ธ **Free Game Radar**
|
| 72 |
+
Stay updated with the latest **limited-time free games** from:
|
| 73 |
+
- ๐ฎ Epic Games Store
|
| 74 |
+
- ๐ข Steam giveaways
|
| 75 |
|
| 76 |
+
Click the button below to scan today's free offers ๐
|
| 77 |
+
""")
|
| 78 |
|
| 79 |
+
with gr.Row():
|
| 80 |
+
check_button = gr.Button("๐ Check Free Games", scale=2, variant="primary")
|
| 81 |
+
|
| 82 |
+
with gr.Row():
|
| 83 |
+
gallery = gr.Gallery(label="๐ข Steam Game Covers", show_label=True, columns=2).style(height="auto")
|
| 84 |
+
|
| 85 |
+
with gr.Row():
|
| 86 |
+
summary = gr.Textbox(label="๐ Game Summary", lines=20, interactive=False)
|
| 87 |
|
| 88 |
+
with gr.Row():
|
| 89 |
+
download = gr.File(label="โฌ๏ธ Download Game List")
|
| 90 |
+
|
| 91 |
+
check_button.click(fn=generate_free_game_data, inputs=[], outputs=[gallery, summary, download])
|
| 92 |
+
|
| 93 |
+
demo.launch()
|