Skip to content

Commit

Permalink
image downloader and image url list started, not tested
Browse files Browse the repository at this point in the history
LoadingStill committed Dec 29, 2024
1 parent 9729f31 commit 2769870
Showing 4 changed files with 49 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# USER_IMAGES_PATH=./path/to/your/images
# USER_IMAGES_PATH=./path/to/your/images

USER_IMAGES_PATH=D:\Docker\WebGSM\Images
4 changes: 3 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from flask import Flask, render_template, request, jsonify
from flask import Flask, render_template, request, jsonify, redirect, url_for
from game_data import game_pages # Import the game_pages dictionary
import os
import subprocess

app = Flask(__name__)

39 changes: 39 additions & 0 deletions static/images/image_downloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import json
import requests

# Path to the JSON file containing the game data
json_file = 'image_urls.json'

# Folder where images will be saved
save_folder = './static/images'

# Ensure the save folder exists
if not os.path.exists(save_folder):
os.makedirs(save_folder)

# Function to download and save the image
def download_image(image_url, save_path):
try:
# Send a GET request to the image URL
response = requests.get(image_url)
# Check if the request was successful
if response.status_code == 200:
# Open the file in write-binary mode and save the content
with open(save_path, 'wb') as file:
file.write(response.content)
print(f"Downloaded image and saved as {save_path}")
else:
print(f"Failed to download {image_url}, status code: {response.status_code}")
except Exception as e:
print(f"Error downloading {image_url}: {e}")

# Load the JSON file containing the image URLs
with open(json_file, 'r') as file:
game_data = json.load(file)

# Iterate over each entry in the JSON data
for game in game_data:
game_name, rename_to, image_url = game
save_path = os.path.join(save_folder, rename_to)
download_image(image_url, save_path)
4 changes: 4 additions & 0 deletions static/images/image_urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
["cs2", "cs2.jpg", "https://cdn.cloudflare.steamstatic.com/steam/apps/730/library_600x900.jpg"],
["factorio", "fctr.jpg", "https://cdn.cloudflare.steamstatic.com/steam/apps/427520/library_600x900.jpg?t=1597145422"]
]

0 comments on commit 2769870

Please sign in to comment.