diff options
| author | user@node5.net <user@node5.net> | 2026-04-14 22:17:33 +0200 |
|---|---|---|
| committer | user@node5.net <user@node5.net> | 2026-04-14 22:17:33 +0200 |
| commit | 7fe279ada3c9a23d78e882b76bd95ef774b43a8e (patch) | |
| tree | ff46b0e7ce56db3abb98e6c32578c7bb26a45886 /enroll.py | |
| parent | 029671f77da344a1326e413e93939574eae4f891 (diff) | |
| parent | 9b01d51a610a26141ef0f21d1b61c681d46d2426 (diff) | |
merge upstream main 2026-04-14 onto map libremaplibre
some functionalities still broken
Diffstat (limited to 'enroll.py')
| -rw-r--r-- | enroll.py | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -4,6 +4,7 @@ import sys import re import json import os +from datetime import date from exif import Image as ExifImage from PIL import Image as PILImage import urllib.parse @@ -21,7 +22,7 @@ def to_dec_deg(input_string): return (float(deg) + float(minutes)/60 + float(seconds)/(60*60)) * (-1 if direction in ['W', 'S'] else 1) def prompt_for_coordinates(): - coord_input = input("Enter coordinates in format: lat, lng (e.g., 40.23123, 12.21314): ").strip() + coord_input = input("Enter coordinates in format: lat, lng (e.g., 55.123123, 12.123123): ").strip() try: lat_str, lon_str = map(str.strip, coord_input.split(",")) return float(lat_str), float(lon_str) @@ -39,7 +40,7 @@ def clean_and_resize_image(image_path, width=1920): # Resize and strip EXIF img = img.resize((width, height), PILImage.LANCZOS) img_no_exif = PILImage.new(img.mode, img.size) - img_no_exif.putdata(list(img.getdata())) + img_no_exif.putdata(list(img.get_flattened_data())) img_no_exif.save(image_path) print(f"Image resized to {width}px wide and EXIF removed: {image_path}") except Exception as e: @@ -75,10 +76,10 @@ def main(): print("No GPS data found in the image.") lat_dec_deg, lon_dec_deg = prompt_for_coordinates() - # Resize and strip EXIF - clean_and_resize_image(filename) + if "-q" not in sys.argv: + print("Reformatting image...") + clean_and_resize_image(filename) - # URL encode symbols in image filename to ensure image loads filename_encoded = urllib.parse.quote(filename) new_entry = { @@ -86,11 +87,11 @@ def main(): "lat": round(lat_dec_deg, 6), "lng": round(lon_dec_deg, 6), "authors": authors, - "image": filename_encoded + "image": filename_encoded, + "date": date.today().isoformat() } } - # Load existing data if os.path.exists(DATA_FILE): with open(DATA_FILE, 'r', encoding='utf-8') as f: try: @@ -100,11 +101,9 @@ def main(): else: existing_data = {} - # Add and sort quotes alphabetically existing_data.update(new_entry) sorted_data = dict(sorted(existing_data.items(), key=lambda item: item[0].lower())) - # Write updated JSON with minimal diff noise with open(DATA_FILE, 'w', encoding='utf-8', newline='\n') as f: json.dump(sorted_data, f, indent=4, separators=(',', ': ')) f.write('\n') |
