mirror of https://gitlab.com/bashrc2/epicyon
Update address book when posts with addresses are received
parent
eb0d021518
commit
3f85198737
20
maps.py
20
maps.py
|
@ -97,6 +97,26 @@ def _get_location_from_tags(tags: []) -> str:
|
|||
return None
|
||||
|
||||
|
||||
def update_address_book(base_dir: str, nickname: str, domain: str,
|
||||
location: str, address: str) -> None:
|
||||
"""Adds an address to the address book for the given account
|
||||
"""
|
||||
address_book_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/addresses.json'
|
||||
address_book_dict = {}
|
||||
if os.path.isfile(address_book_filename):
|
||||
address_book_dict2 = load_json(address_book_filename)
|
||||
if address_book_dict2:
|
||||
address_book_dict = address_book_dict2
|
||||
address = remove_html(address)
|
||||
if address_book_dict.get(location):
|
||||
if address_book_dict[location] == address:
|
||||
# already exists so we don't need to update
|
||||
return
|
||||
address_book_dict[location] = address
|
||||
save_json(address_book_dict, address_book_filename)
|
||||
|
||||
|
||||
def get_location_from_post(post_json_object: {}) -> str:
|
||||
"""Returns the location for the given post
|
||||
"""
|
||||
|
|
|
@ -125,6 +125,7 @@ from cwlists import add_cw_from_lists
|
|||
from blocking import is_blocked
|
||||
from blocking import sending_is_blocked2
|
||||
from reaction import html_emoji_reactions
|
||||
from maps import update_address_book
|
||||
from maps import html_open_street_map
|
||||
from maps import set_map_preferences_coords
|
||||
from maps import set_map_preferences_url
|
||||
|
@ -3188,6 +3189,11 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
# if this is a location with an address then remove the address
|
||||
if '<br><address>' in location_str:
|
||||
loc_str = location_str.split('<br><address>')[0]
|
||||
loc_address = location_str.split('<br><address>')[1]
|
||||
if '</address>' in loc_address:
|
||||
loc_address = loc_address.split('</address>')[0]
|
||||
update_address_book(base_dir, nickname, domain,
|
||||
loc_str, loc_address)
|
||||
# does this look like a geolocation link?
|
||||
if resembles_url(loc_str):
|
||||
bounding_box_degrees = 0.001
|
||||
|
|
Loading…
Reference in New Issue