summaryrefslogtreecommitdiff
path: root/enroll.py
diff options
context:
space:
mode:
Diffstat (limited to 'enroll.py')
-rw-r--r--enroll.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/enroll.py b/enroll.py
index 7cb25d3..82e994d 100644
--- a/enroll.py
+++ b/enroll.py
@@ -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')