mirror of https://gitlab.com/bashrc2/epicyon
Handle location url
parent
5807d29f11
commit
36544e214e
25
happening.py
25
happening.py
|
|
@ -14,6 +14,7 @@ from datetime import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from flags import is_reminder
|
from flags import is_reminder
|
||||||
from flags import is_public_post
|
from flags import is_public_post
|
||||||
|
from utils import resembles_url
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
from utils import date_from_numbers
|
from utils import date_from_numbers
|
||||||
from utils import date_from_string_format
|
from utils import date_from_string_format
|
||||||
|
|
@ -944,6 +945,7 @@ def _dav_store_event(base_dir: str, nickname: str, domain: str,
|
||||||
start_time = None
|
start_time = None
|
||||||
end_time = None
|
end_time = None
|
||||||
description = None
|
description = None
|
||||||
|
location = None
|
||||||
for line in event_list:
|
for line in event_list:
|
||||||
if line.startswith('DTSTAMP:'):
|
if line.startswith('DTSTAMP:'):
|
||||||
timestamp = line.split(':', 1)[1]
|
timestamp = line.split(':', 1)[1]
|
||||||
|
|
@ -1060,18 +1062,37 @@ def _dav_store_event(base_dir: str, nickname: str, domain: str,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if location:
|
if location:
|
||||||
event_json['object']['tag'].append({
|
# get the location link
|
||||||
|
location_url = ''
|
||||||
|
if '://' in location:
|
||||||
|
location_words = location.split(' ')
|
||||||
|
for loc_wrd in location_words:
|
||||||
|
if '://' in loc_wrd:
|
||||||
|
if resembles_url(loc_wrd):
|
||||||
|
location_url = loc_wrd
|
||||||
|
# remove link from the location name
|
||||||
|
location = location.replace(location_url, '')
|
||||||
|
location = location.replace(' ', ' ')
|
||||||
|
break
|
||||||
|
# add a tag
|
||||||
|
location_tag = {
|
||||||
'@context': [
|
'@context': [
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'https://w3id.org/security/v1'
|
'https://w3id.org/security/v1'
|
||||||
],
|
],
|
||||||
'type': 'Place',
|
'type': 'Place',
|
||||||
'name': location
|
'name': location
|
||||||
})
|
}
|
||||||
|
event_json['object']['tag'].append(location_tag)
|
||||||
|
# add a location to the object
|
||||||
event_json['object']['location'] = {
|
event_json['object']['location'] = {
|
||||||
'type': 'Place',
|
'type': 'Place',
|
||||||
'name': location
|
'name': location
|
||||||
}
|
}
|
||||||
|
if location_url:
|
||||||
|
# add the url to the location
|
||||||
|
event_json['object']['location']['url'] = location_url
|
||||||
|
location_tag['url'] = location_url
|
||||||
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'
|
||||||
|
|
|
||||||
21
maps.py
21
maps.py
|
|
@ -10,6 +10,7 @@ __module_group__ = "Core"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from flags import is_float
|
from flags import is_float
|
||||||
|
from utils import resembles_url
|
||||||
from utils import browser_supports_download_filename
|
from utils import browser_supports_download_filename
|
||||||
from utils import get_url_from_post
|
from utils import get_url_from_post
|
||||||
from utils import acct_dir
|
from utils import acct_dir
|
||||||
|
|
@ -54,7 +55,15 @@ def _get_location_from_tags(tags: []) -> str:
|
||||||
locn = get_location_dict_from_tags(tags)
|
locn = get_location_dict_from_tags(tags)
|
||||||
if locn:
|
if locn:
|
||||||
location_str = locn['name'].replace('\n', ' ')
|
location_str = locn['name'].replace('\n', ' ')
|
||||||
return remove_html(location_str)
|
location_str = remove_html(location_str)
|
||||||
|
if locn.get('url'):
|
||||||
|
if isinstance(locn['url'], str):
|
||||||
|
if resembles_url(locn['url']):
|
||||||
|
location_str = \
|
||||||
|
'<a href="' + locn['url'] + '" target="_blank" ' + \
|
||||||
|
'rel="nofollow noopener noreferrer">' + \
|
||||||
|
location_str + '</a>'
|
||||||
|
return location_str
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -62,6 +71,7 @@ def get_location_from_post(post_json_object: {}) -> str:
|
||||||
"""Returns the location for the given post
|
"""Returns the location for the given post
|
||||||
"""
|
"""
|
||||||
locn = None
|
locn = None
|
||||||
|
locn_url = None
|
||||||
|
|
||||||
# location represented via a tag
|
# location represented via a tag
|
||||||
post_obj = post_json_object
|
post_obj = post_json_object
|
||||||
|
|
@ -88,12 +98,21 @@ def get_location_from_post(post_json_object: {}) -> str:
|
||||||
if locn2.get('name'):
|
if locn2.get('name'):
|
||||||
if isinstance(locn2['name'], str):
|
if isinstance(locn2['name'], str):
|
||||||
locn = locn2['name']
|
locn = locn2['name']
|
||||||
|
if locn2.get('url'):
|
||||||
|
if isinstance(locn2['url'], str):
|
||||||
|
locn_url = locn2['url']
|
||||||
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,
|
||||||
locn2['latitude'],
|
locn2['latitude'],
|
||||||
locn2['longitude'])
|
locn2['longitude'])
|
||||||
|
elif locn_url:
|
||||||
|
if locn:
|
||||||
|
locn = '<a href="' + locn_url + '" target="_blank" ' + \
|
||||||
|
'rel="nofollow noopener noreferrer">' + locn + '</a>'
|
||||||
|
else:
|
||||||
|
locn = locn_url
|
||||||
|
|
||||||
return locn
|
return locn
|
||||||
|
|
||||||
|
|
|
||||||
10
posts.py
10
posts.py
|
|
@ -41,6 +41,7 @@ from flags import contains_private_key
|
||||||
from flags import has_group_type
|
from flags import has_group_type
|
||||||
from flags import is_premium_account
|
from flags import is_premium_account
|
||||||
from flags import url_permitted
|
from flags import url_permitted
|
||||||
|
from utils import resembles_url
|
||||||
from utils import get_person_icon
|
from utils import get_person_icon
|
||||||
from utils import remove_post_from_index
|
from utils import remove_post_from_index
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
|
|
@ -1397,7 +1398,10 @@ def _create_post_s2s(base_dir: str, nickname: str, domain: str, port: int,
|
||||||
'type': 'Place',
|
'type': 'Place',
|
||||||
'name': location['name']
|
'name': location['name']
|
||||||
}
|
}
|
||||||
|
if location.get('url'):
|
||||||
|
if isinstance(location['url'], str):
|
||||||
|
if resembles_url(location['url']):
|
||||||
|
new_post['object']['location']['url'] = location['url']
|
||||||
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,
|
||||||
|
|
@ -1529,6 +1533,10 @@ def _create_post_c2s(base_dir: str, nickname: str, domain: str, port: int,
|
||||||
'type': 'Place',
|
'type': 'Place',
|
||||||
'name': location['name']
|
'name': location['name']
|
||||||
}
|
}
|
||||||
|
if location.get('url'):
|
||||||
|
if isinstance(location['url'], str):
|
||||||
|
if resembles_url(location['url']):
|
||||||
|
new_post['object']['location']['url'] = location['url']
|
||||||
|
|
||||||
if attach_image_filename:
|
if attach_image_filename:
|
||||||
new_post = \
|
new_post = \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue