Files
aydogannakliyat/scratch/update_images.py
2026-04-16 01:36:18 +03:00

35 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import re
# Mapping of service title to subdirectory name
mapping = {
"Sandiviç Panel İndirme Kaldırma": "sandiviçpanelindirmekaldırma",
"Konteyner Nakliyesi & Tiny House Kaldırma": "Konteyner nakliyesi Tiny house kaldırma",
"Jet Ground Kaldırma Taşıma": "Jet ground kaldırma taşıma",
"Vinç Hizmetleri": "Vinç hizmetleri",
"Sepetli Platform Hizmetleri": "Sepetli platform hizmetleri",
"Tekne ve Yat Kaldırma": "Tekne yat kaldırma",
"Nakliyat ve Taşımacılık": "Nakliyat-Taşımacılık"
}
data_file = 'lib/data.ts'
with open(data_file, 'r', encoding='utf-8') as f:
content = f.read()
for title, subdir in mapping.items():
image_dir = os.path.join('public/images', subdir)
if os.path.exists(image_dir):
files = [f for f in os.listdir(image_dir) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.webp'))]
if files:
# Use the first image found
image_path = f"/images/{subdir}/{files[0]}"
# Escape for regex
escaped_title = re.escape(title)
pattern = rf'(title:\s*"{escaped_title}",\s*description:\s*".*?",\s*image:\s*")([^"]+)(")'
content = re.sub(pattern, rf'\1{image_path}\3', content)
with open(data_file, 'w', encoding='utf-8') as f:
f.write(content)
print("Successfully updated lib/data.ts with local images.")