Erster Commit
This commit is contained in:
commit
773fdc4edd
52
ConvertImageToWebp.py
Normal file
52
ConvertImageToWebp.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import os
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
def convert_images_to_webp(directory):
|
||||||
|
"""
|
||||||
|
Converts all image files in the specified directory to webp format.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
directory (str): The path to the directory containing the image files to convert.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Supported image extensions
|
||||||
|
supported_extensions = [".jpg", ".jpeg", ".png", ".bmp", ".tiff"]
|
||||||
|
|
||||||
|
# List all files in the directory
|
||||||
|
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
||||||
|
|
||||||
|
if not files:
|
||||||
|
print("No files found in the directory.")
|
||||||
|
return
|
||||||
|
|
||||||
|
for file_name in files:
|
||||||
|
# Get the file extension
|
||||||
|
file_extension = os.path.splitext(file_name)[1].lower()
|
||||||
|
if file_extension not in supported_extensions:
|
||||||
|
continue # Skip unsupported files
|
||||||
|
|
||||||
|
# Open the image
|
||||||
|
old_path = os.path.join(directory, file_name)
|
||||||
|
try:
|
||||||
|
with Image.open(old_path) as img:
|
||||||
|
# Construct the new file name
|
||||||
|
new_name = os.path.splitext(file_name)[0] + ".webp"
|
||||||
|
new_path = os.path.join(directory, new_name)
|
||||||
|
# Save as webp
|
||||||
|
img.save(new_path, "webp")
|
||||||
|
print(f"Converted: {old_path} -> {new_path}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to convert {file_name}: {e}")
|
||||||
|
|
||||||
|
print("All supported images have been converted to webp format.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
if __name__ == "__main__":
|
||||||
|
folder_path = input("Enter the path to the folder: ").strip()
|
||||||
|
if os.path.isdir(folder_path):
|
||||||
|
convert_images_to_webp(folder_path)
|
||||||
|
else:
|
||||||
|
print("The provided path is not a valid directory.")
|
||||||
|
Z:\Geschäft\Kunden\BestHeat - Roy Curth\Landing-Page\Diashow Produkte\Bilder\Industrieheizung
|
||||||
40
JsonTranslating.py
Normal file
40
JsonTranslating.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import json
|
||||||
|
from deep_translator import GoogleTranslator
|
||||||
|
|
||||||
|
def translate_json():
|
||||||
|
# Dateiname abfragen
|
||||||
|
input_file = input("Bitte den Pfad zur JSON-Datei eingeben: ")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# JSON-Datei einlesen
|
||||||
|
with open(input_file, 'r', encoding='utf-8') as file:
|
||||||
|
data = json.load(file)
|
||||||
|
|
||||||
|
# Übersetzer initialisieren
|
||||||
|
translator = GoogleTranslator(source='de', target='fr')
|
||||||
|
|
||||||
|
# Werte übersetzen
|
||||||
|
print("Übersetzung läuft...")
|
||||||
|
for key, value in data.items():
|
||||||
|
if isinstance(value, str): # Nur Strings übersetzen
|
||||||
|
data[key] = translator.translate(value)
|
||||||
|
|
||||||
|
# Ausgabe-Dateiname generieren
|
||||||
|
output_file = input_file.replace('.json', '-translated.json')
|
||||||
|
|
||||||
|
# Übersetzte Datei speichern"C:\Users\chris\Desktop\de-DE.json"
|
||||||
|
with open(output_file, 'w', encoding='utf-8') as file:
|
||||||
|
json.dump(data, file, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
print(f"Übersetzung abgeschlossen. Datei gespeichert als '{output_file}'")
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Fehler: Datei nicht gefunden. Bitte überprüfen Sie den Pfad.")
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
print("Fehler: Ungültiges JSON-Format. Bitte überprüfen Sie die Datei.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Ein unerwarteter Fehler ist aufgetreten: {e}")
|
||||||
|
|
||||||
|
# Skript ausführen
|
||||||
|
if __name__ == "__main__":
|
||||||
|
translate_json()
|
||||||
49
RenameFiles.py
Normal file
49
RenameFiles.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
def rename_files_in_directory(directory):
|
||||||
|
"""
|
||||||
|
Renames all files in the specified directory based on user input for the base name.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
directory (str): The path to the directory containing the files to rename.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# List all files in the directory
|
||||||
|
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
||||||
|
|
||||||
|
if not files:
|
||||||
|
print("No files found in the directory.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Ask the user for the base name
|
||||||
|
base_name = input("Enter the base name for the files (e.g., 'Test'): ")
|
||||||
|
if not base_name:
|
||||||
|
print("Base name cannot be empty.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Sort files alphabetically (optional)
|
||||||
|
files.sort()
|
||||||
|
|
||||||
|
for index, file_name in enumerate(files, start=1):
|
||||||
|
# Get the file extension
|
||||||
|
file_extension = os.path.splitext(file_name)[1]
|
||||||
|
# Construct the new file name
|
||||||
|
new_name = f"{base_name}{index}{file_extension}"
|
||||||
|
# Get the full paths
|
||||||
|
old_path = os.path.join(directory, file_name)
|
||||||
|
new_path = os.path.join(directory, new_name)
|
||||||
|
# Rename the file
|
||||||
|
os.rename(old_path, new_path)
|
||||||
|
print(f"Renamed: {old_path} -> {new_path}")
|
||||||
|
|
||||||
|
print("All files have been renamed successfully.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
if __name__ == "__main__":
|
||||||
|
folder_path = input("Enter the path to the folder: ").strip()
|
||||||
|
if os.path.isdir(folder_path):
|
||||||
|
rename_files_in_directory(folder_path)
|
||||||
|
else:
|
||||||
|
print("The provided path is not a valid directory.")
|
||||||
Loading…
Reference in New Issue
Block a user