More compatibility with pixelfed stle location representation

merge-requests/30/head
Bob Mottram 2023-08-03 14:45:47 +01:00
parent dd5a353c95
commit c0375fbf73
4 changed files with 65 additions and 2 deletions

View File

@ -963,6 +963,10 @@ def _dav_store_event(base_dir: str, nickname: str, domain: str,
"type": "Place", "type": "Place",
"name": location "name": location
}) })
event_json['object']['location'] = {
'type': 'Place',
'name': location
}
handle = nickname + '@' + domain handle = nickname + '@' + domain
handle_dir = acct_handle_dir(base_dir, handle) handle_dir = acct_handle_dir(base_dir, handle)
outbox_dir = handle_dir + '/outbox' outbox_dir = handle_dir + '/outbox'

18
maps.py
View File

@ -27,7 +27,7 @@ def _geocoords_to_osm_link(osm_domain: str, zoom: int,
str(zoom) + '/' + str(latitude) + '/' + str(longitude) str(zoom) + '/' + str(latitude) + '/' + str(longitude)
def _get_location_from_tags(tags: []) -> str: def get_location_dict_from_tags(tags: []) -> str:
"""Returns the location from the tags list """Returns the location from the tags list
""" """
for tag_item in tags: for tag_item in tags:
@ -39,7 +39,16 @@ def _get_location_from_tags(tags: []) -> str:
continue continue
if not isinstance(tag_item['name'], str): if not isinstance(tag_item['name'], str):
continue continue
location_str = tag_item['name'].replace('\n', ' ') return tag_item
return None
def _get_location_from_tags(tags: []) -> str:
"""Returns the location from the tags list
"""
locn = get_location_dict_from_tags(tags)
if locn:
location_str = locn['name'].replace('\n', ' ')
return remove_html(location_str) return remove_html(location_str)
return None return None
@ -68,12 +77,17 @@ def get_location_from_post(post_json_object: {}) -> str:
if is_float(post_obj['location']['longitude']) and \ if is_float(post_obj['location']['longitude']) and \
is_float(post_obj['location']['latitude']): is_float(post_obj['location']['latitude']):
locn_exists = True locn_exists = True
if not locn_exists:
if post_obj['location'].get('name'):
if isinstance(post_obj['location']['name'], str):
locn = post_obj['location']['name']
if locn_exists: if locn_exists:
osm_domain = 'osm.org' osm_domain = 'osm.org'
zoom = 17 zoom = 17
locn = _geocoords_to_osm_link(osm_domain, zoom, locn = _geocoords_to_osm_link(osm_domain, zoom,
post_obj['location']['latitude'], post_obj['location']['latitude'],
post_obj['location']['longitude']) post_obj['location']['longitude'])
return locn return locn

View File

@ -102,6 +102,7 @@ from linked_data_sig import generate_json_signature
from petnames import resolve_petnames from petnames import resolve_petnames
from video import convert_video_to_note from video import convert_video_to_note
from context import get_individual_post_context from context import get_individual_post_context
from maps import get_location_dict_from_tags
from maps import geocoords_from_map_link from maps import geocoords_from_map_link
from keys import get_person_key from keys import get_person_key
from markdown import markdown_to_html from markdown import markdown_to_html
@ -1280,6 +1281,25 @@ def _create_post_s2s(base_dir: str, nickname: str, domain: str, port: int,
"crawlable": False "crawlable": False
} }
} }
# pixelfed style location representation
location = get_location_dict_from_tags(tags)
if location:
if location.get('name') and \
location.get('longitude') and \
location.get('latitude'):
new_post['object']['location'] = {
'type': 'Place',
'name': location['name'],
'longitude': location['longitude'],
'latitude': location['latitude']
}
elif location.get('name'):
new_post['object']['location'] = {
'type': 'Place',
'name': location['name']
}
if attach_image_filename: if attach_image_filename:
new_post['object'] = \ new_post['object'] = \
attach_media(base_dir, http_prefix, nickname, domain, port, attach_media(base_dir, http_prefix, nickname, domain, port,
@ -1354,6 +1374,25 @@ def _create_post_c2s(base_dir: str, nickname: str, domain: str, port: int,
}, },
"crawlable": False "crawlable": False
} }
# pixelfed style location representation
location = get_location_dict_from_tags(tags)
if location:
if location.get('name') and \
location.get('longitude') and \
location.get('latitude'):
new_post['location'] = {
'type': 'Place',
'name': location['name'],
'longitude': location['longitude'],
'latitude': location['latitude']
}
elif location.get('name'):
new_post['location'] = {
'type': 'Place',
'name': location['name']
}
if attach_image_filename: if attach_image_filename:
new_post = \ new_post = \
attach_media(base_dir, http_prefix, nickname, domain, port, attach_media(base_dir, http_prefix, nickname, domain, port,

View File

@ -609,11 +609,17 @@ def get_shares_collection(actor: str, page_number: int, items_per_page: int,
"value": shared_item['category'] "value": shared_item['category']
}) })
if shared_item['location']: if shared_item['location']:
# tag representation of location
offer_item['object']['attachment'].append({ offer_item['object']['attachment'].append({
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
"type": "Place", "type": "Place",
"name": shared_item['location'].title() "name": shared_item['location'].title()
}) })
# pixelfed style representation of location
offer_item['object']['location'] = {
"type": "Place",
"name": shared_item['location'].title()
}
if shared_item['imageUrl']: if shared_item['imageUrl']:
if '://' in shared_item['imageUrl']: if '://' in shared_item['imageUrl']:
file_extension = None file_extension = None