-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
image downloader and image url list started, not tested
- Loading branch information
1 parent
9729f31
commit 2769870
Showing
4 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
] |