|
from datasets import load_dataset |
|
import json |
|
import os |
|
import zipfile |
|
|
|
|
|
dataset = load_dataset("maringetxway/local")["train"] |
|
|
|
|
|
os.makedirs("map_project", exist_ok=True) |
|
|
|
|
|
with open("map_project/data.json", "w") as f: |
|
json.dump(dataset[:], f) |
|
|
|
|
|
index_html = """<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<title>World Map from Hugging Face Dataset</title> |
|
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" /> |
|
<style> |
|
html, body { |
|
margin: 0; |
|
padding: 0; |
|
} |
|
#map { |
|
height: 100vh; |
|
width: 100%; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div id="map"></div> |
|
|
|
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script> |
|
<script src="script.js"></script> |
|
</body> |
|
</html> |
|
""" |
|
with open("map_project/index.html", "w") as f: |
|
f.write(index_html) |
|
|
|
|
|
script_js = """const map = L.map('map').setView([20, 0], 2); |
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
|
attribution: '© OpenStreetMap contributors' |
|
}).addTo(map); |
|
|
|
fetch('data.json') |
|
.then(response => response.json()) |
|
.then(data => { |
|
data.forEach(entry => { |
|
const lat = parseFloat(entry.latitude || entry.Latitude); |
|
const lng = parseFloat(entry.longitude || entry.Longitude); |
|
const name = entry.name || entry.Name || 'Unknown'; |
|
const desc = entry.description || entry.Description || ''; |
|
|
|
if (!isNaN(lat) && !isNaN(lng)) { |
|
L.marker([lat, lng]) |
|
.addTo(map) |
|
.bindPopup(`<strong>${name}</strong><br>${desc}`); |
|
} |
|
}); |
|
}); |
|
""" |
|
with open("map_project/script.js", "w") as f: |
|
f.write(script_js) |
|
|
|
|
|
with zipfile.ZipFile("world_map_project.zip", "w") as zipf: |
|
for foldername, subfolders, filenames in os.walk("map_project"): |
|
for filename in filenames: |
|
filepath = os.path.join(foldername, filename) |
|
zipf.write(filepath, os.path.relpath(filepath, "map_project")) |
|
|
|
print("β
Done! File saved as world_map_project.zip") |
|
|