diff --git a/daemon_post_profile.py b/daemon_post_profile.py index 43a1cfeb2..4e8591b24 100644 --- a/daemon_post_profile.py +++ b/daemon_post_profile.py @@ -2959,9 +2959,10 @@ def profile_edit(self, calling_domain: str, cookie: str, if self.server.low_bandwidth: convert_image_to_low_bandwidth(filename) + exif_json: list[dict] = [] process_meta_data(base_dir, nickname, domain, filename, post_image_filename, city, - content_license_url) + content_license_url, exif_json) if os.path.isfile(post_image_filename): print('profile update POST ' + m_type + ' image, zip or font saved to ' + diff --git a/daemon_post_receive.py b/daemon_post_receive.py index 2deb2f313..88df05a7f 100644 --- a/daemon_post_receive.py +++ b/daemon_post_receive.py @@ -64,6 +64,7 @@ from cache import remove_person_from_cache from cache import get_person_from_cache from shares import add_shares_to_actor from person import get_actor_update_json +from maps import geocoords_to_osm_link NEW_POST_SUCCESS = 1 NEW_POST_FAILED = -1 @@ -1860,6 +1861,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, else: print('DEBUG: no media filename in POST') + exif_json: list[dict] = [] if filename: if is_image_file(filename): # convert to low bandwidth if needed @@ -1875,10 +1877,11 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, city = get_spoofed_city(city, base_dir, nickname, domain) process_meta_data(base_dir, nickname, domain, filename, post_image_filename, city, - content_license_url) + content_license_url, exif_json) if os.path.isfile(post_image_filename): print('POST media saved to ' + post_image_filename) else: + exif_json = [] print('ERROR: POST media could not be saved to ' + post_image_filename) else: @@ -1953,6 +1956,33 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, fields['eventEndTime'] = None if not fields.get('location'): fields['location'] = None + if exif_json: + # convert the exif geolocation into an OSM link + latitude = None + longitude = None + for property_dict in exif_json: + if not isinstance(property_dict, dict): + continue + if not property_dict.get('name') or \ + not property_dict.get('value'): + continue + if not isinstance(property_dict['name'], str): + continue + if property_dict['name'] == "GPSLongitude": + longitude = property_dict['value'] + if not isinstance(longitude, float): + longitude = float(longitude) + if property_dict['name'] == "GPSLatitude": + latitude = property_dict['value'] + if not isinstance(latitude, float): + longitude = float(latitude) + if latitude is not None and \ + longitude is not None: + osm_domain = 'osm.org' + zoom = 17 + fields['location'] = \ + geocoords_to_osm_link(osm_domain, zoom, + latitude, longitude) if not fields.get('locationAddress'): fields['locationAddress'] = None if not fields.get('languagesDropdown'): diff --git a/maps.py b/maps.py index 0029fc012..d235ccaa1 100644 --- a/maps.py +++ b/maps.py @@ -25,8 +25,8 @@ from timeFunctions import date_utcnow from session import get_resolved_url -def _geocoords_to_osm_link(osm_domain: str, zoom: int, - latitude: float, longitude: float) -> str: +def geocoords_to_osm_link(osm_domain: str, zoom: int, + latitude: float, longitude: float) -> str: """Returns an OSM link for the given geocoordinates """ return 'https://www.' + osm_domain + '/#map=' + \ @@ -280,9 +280,9 @@ def get_location_from_post(post_json_object: {}) -> str: # location geocoordinate osm_domain = 'osm.org' zoom = 17 - locn = _geocoords_to_osm_link(osm_domain, zoom, - locn2['latitude'], - locn2['longitude']) + locn = geocoords_to_osm_link(osm_domain, zoom, + locn2['latitude'], + locn2['longitude']) elif locn_url: # location name and link if locn: @@ -814,7 +814,7 @@ def html_open_street_map(url: str, return '' if not zoom: return '' - osm_url = _geocoords_to_osm_link(osm_domain, zoom, latitude, longitude) + osm_url = geocoords_to_osm_link(osm_domain, zoom, latitude, longitude) html_str = \ '