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

46 lines
1.8 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 for ServicesPreview since it has different titles/structure
preview_mapping = {
"ır Nakliyat": "Nakliyat-Taşımacılık",
"Mobil Vinç": "Vinç hizmetleri",
"Sepetli Platform": "Sepetli platform hizmetleri"
}
preview_file = 'components/ServicesPreview.tsx'
if os.path.exists(preview_file):
with open(preview_file, 'r', encoding='utf-8') as f:
content = f.read()
for title, subdir in preview_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:
image_path = f"/images/{subdir}/{files[0]}"
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(preview_file, 'w', encoding='utf-8') as f:
f.write(content)
print("Updated ServicesPreview.tsx")
# Also update Hero.tsx with a local crane image
hero_file = 'components/Hero.tsx'
if os.path.exists(hero_file):
with open(hero_file, 'r', encoding='utf-8') as f:
content = f.read()
# Use one of the crane images for Hero
image_dir = 'public/images/Vinç hizmetleri'
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:
image_path = f"/images/Vinç hizmetleri/{files[0]}"
content = re.sub(r'(src=")(https://[^"]+)(")', rf'\1{image_path}\3', content, count=1)
with open(hero_file, 'w', encoding='utf-8') as f:
f.write(content)
print("Updated Hero.tsx")