#!/usr/bin/env python3 """ دانلود کتابخانه MapLibre GL JS برای استفاده آفلاین """ import os import urllib.request from pathlib import Path # نسخه مورد نیاز MAPLIBRE_VERSION = "3.6.2" # فایل‌های مورد نیاز FILES = { f"https://unpkg.com/maplibre-gl@{MAPLIBRE_VERSION}/dist/maplibre-gl.js": "maplibre-gl.js", f"https://unpkg.com/maplibre-gl@{MAPLIBRE_VERSION}/dist/maplibre-gl.css": "maplibre-gl.css", f"https://unpkg.com/maplibre-gl@{MAPLIBRE_VERSION}/dist/maplibre-gl.wasm": "maplibre-gl.wasm", } def download_file(url, output_path): """دانلود فایل""" try: print(f"دانلود: {url}") req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'}) with urllib.request.urlopen(req, timeout=30) as response: data = response.read() with open(output_path, 'wb') as f: f.write(data) print(f" ذخیره شد: {output_path}") return True except Exception as e: print(f" خطا: {e}") return False def main(): print(f""" ╔══════════════════════════════════════════════════════════════╗ ║ دانلود MapLibre GL JS v{MAPLIBRE_VERSION} ║ ╚══════════════════════════════════════════════════════════════╝ """) # مسیر خروجی script_dir = Path(__file__).parent.parent js_dir = script_dir / "public" / "assets" / "js" css_dir = script_dir / "public" / "assets" / "css" # ایجاد پوشه‌ها js_dir.mkdir(parents=True, exist_ok=True) css_dir.mkdir(parents=True, exist_ok=True) success_count = 0 for url, filename in FILES.items(): # تعیین مسیر خروجی بر اساس نوع فایل if filename.endswith('.js') or filename.endswith('.wasm'): output_path = js_dir / filename else: output_path = css_dir / filename if download_file(url, output_path): success_count += 1 print(f""" ╔══════════════════════════════════════════════════════════════╗ ║ گزارش نهایی ║ ╠══════════════════════════════════════════════════════════════╣ ║ فایل‌های دانلود شده: {success_count}/{len(FILES)} ║ ╚══════════════════════════════════════════════════════════════╝ """) if success_count == len(FILES): print("همه فایل‌ها با موفقیت دانلود شدند!") print("\nحالا فایل map.php رو بروزرسانی کنید.") else: print("بعضی فایل‌ها دانلود نشدند. لطفاً دوباره تلاش کنید.") if __name__ == "__main__": main()