mirror of https://gitlab.com/bashrc2/epicyon
Add buy link to posts
parent
b9c749b4b9
commit
1b5594bcbd
22
daemon.py
22
daemon.py
|
@ -667,6 +667,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
event_end_time = None
|
||||
location = None
|
||||
conversation_id = None
|
||||
buy_url = ''
|
||||
city = get_spoofed_city(self.server.city,
|
||||
self.server.base_dir,
|
||||
nickname, self.server.domain)
|
||||
|
@ -700,7 +701,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.low_bandwidth,
|
||||
self.server.content_license_url,
|
||||
languages_understood, False,
|
||||
self.server.translate)
|
||||
self.server.translate, buy_url)
|
||||
if message_json:
|
||||
# NOTE: content and contentMap are not required, but we will keep
|
||||
# them in there so that the post does not get filtered out by
|
||||
|
@ -20680,6 +20681,10 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
else:
|
||||
comments_enabled = True
|
||||
|
||||
buy_url = ''
|
||||
if fields.get('buyUrl'):
|
||||
buy_url = fields['buyUrl']
|
||||
|
||||
if post_type == 'newpost':
|
||||
if not fields.get('pinToProfile'):
|
||||
pin_to_profile = False
|
||||
|
@ -20730,7 +20735,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.low_bandwidth,
|
||||
self.server.content_license_url,
|
||||
languages_understood,
|
||||
self.server.translate)
|
||||
self.server.translate, buy_url)
|
||||
if message_json:
|
||||
if edited_postid:
|
||||
recent_posts_cache = self.server.recent_posts_cache
|
||||
|
@ -20870,7 +20875,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.low_bandwidth,
|
||||
self.server.content_license_url,
|
||||
languages_understood,
|
||||
self.server.translate)
|
||||
self.server.translate, buy_url)
|
||||
if message_json:
|
||||
if fields['schedulePost']:
|
||||
return 1
|
||||
|
@ -21035,7 +21040,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.low_bandwidth,
|
||||
self.server.content_license_url,
|
||||
languages_understood,
|
||||
self.server.translate)
|
||||
self.server.translate, buy_url)
|
||||
if message_json:
|
||||
if edited_postid:
|
||||
recent_posts_cache = self.server.recent_posts_cache
|
||||
|
@ -21146,7 +21151,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.low_bandwidth,
|
||||
self.server.content_license_url,
|
||||
languages_understood,
|
||||
self.server.translate)
|
||||
self.server.translate,
|
||||
buy_url)
|
||||
if message_json:
|
||||
if edited_postid:
|
||||
recent_posts_cache = self.server.recent_posts_cache
|
||||
|
@ -21269,7 +21275,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
content_license_url,
|
||||
languages_understood,
|
||||
reply_is_chat,
|
||||
self.server.translate)
|
||||
self.server.translate,
|
||||
buy_url)
|
||||
if message_json:
|
||||
print('DEBUG: posting DM edited_postid ' +
|
||||
str(edited_postid))
|
||||
|
@ -21385,7 +21392,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.low_bandwidth,
|
||||
self.server.content_license_url,
|
||||
languages_understood,
|
||||
False, self.server.translate)
|
||||
False, self.server.translate,
|
||||
buy_url)
|
||||
if message_json:
|
||||
if fields['schedulePost']:
|
||||
return 1
|
||||
|
|
|
@ -528,6 +528,7 @@ def _desktop_reply_to_post(session, post_id: str,
|
|||
event_time = None
|
||||
event_end_time = None
|
||||
location = None
|
||||
buy_url = ''
|
||||
_say_command(say_str, say_str, screenreader, system_language, espeak)
|
||||
if send_post_via_server(signing_priv_key_pem, __version__,
|
||||
base_dir, session, nickname, password,
|
||||
|
@ -540,7 +541,7 @@ def _desktop_reply_to_post(session, post_id: str,
|
|||
system_language, languages_understood,
|
||||
low_bandwidth, content_license_url,
|
||||
event_date, event_time, event_end_time, location,
|
||||
translate, debug, post_id, post_id,
|
||||
translate, buy_url, debug, post_id, post_id,
|
||||
conversation_id, subject) == 0:
|
||||
say_str = 'Reply sent'
|
||||
else:
|
||||
|
@ -602,6 +603,7 @@ def _desktop_new_post(session,
|
|||
event_time = None
|
||||
event_end_time = None
|
||||
location = None
|
||||
buy_url = ''
|
||||
_say_command(say_str, say_str, screenreader, system_language, espeak)
|
||||
if send_post_via_server(signing_priv_key_pem, __version__,
|
||||
base_dir, session, nickname, password,
|
||||
|
@ -614,7 +616,7 @@ def _desktop_new_post(session,
|
|||
system_language, languages_understood,
|
||||
low_bandwidth, content_license_url,
|
||||
event_date, event_time, event_end_time, location,
|
||||
translate, debug, None, None,
|
||||
translate, buy_url, debug, None, None,
|
||||
conversation_id, subject) == 0:
|
||||
say_str = 'Post sent'
|
||||
else:
|
||||
|
@ -1345,6 +1347,7 @@ def _desktop_new_dm_base(session, to_handle: str,
|
|||
event_time = None
|
||||
event_end_time = None
|
||||
location = None
|
||||
buy_url = ''
|
||||
|
||||
say_str = 'Sending'
|
||||
_say_command(say_str, say_str, screenreader, system_language, espeak)
|
||||
|
@ -1359,7 +1362,7 @@ def _desktop_new_dm_base(session, to_handle: str,
|
|||
system_language, languages_understood,
|
||||
low_bandwidth, content_license_url,
|
||||
event_date, event_time, event_end_time, location,
|
||||
translate, debug, None, None,
|
||||
translate, buy_url, debug, None, None,
|
||||
conversation_id, subject) == 0:
|
||||
say_str = 'Direct message sent'
|
||||
else:
|
||||
|
|
22
epicyon.py
22
epicyon.py
|
@ -149,6 +149,9 @@ def _command_options() -> None:
|
|||
parser.add_argument('--eventLocation', type=str,
|
||||
default=None,
|
||||
help='Location for an event when sending a c2s post')
|
||||
parser.add_argument('--buyUrl', type=str,
|
||||
default=None,
|
||||
help='Link for buying something')
|
||||
parser.add_argument('--content_license_url', type=str,
|
||||
default='https://creativecommons.org/' +
|
||||
'licenses/by-nc/4.0',
|
||||
|
@ -1702,7 +1705,7 @@ def _command_options() -> None:
|
|||
argb.low_bandwidth,
|
||||
argb.content_license_url,
|
||||
argb.eventDate, argb.eventTime, argb.eventEndTime,
|
||||
argb.eventLocation, translate,
|
||||
argb.eventLocation, translate, argb.buyUrl,
|
||||
argb.debug,
|
||||
reply_to, reply_to, argb.conversationId, subject)
|
||||
for _ in range(10):
|
||||
|
@ -3375,6 +3378,7 @@ def _command_options() -> None:
|
|||
low_bandwidth = False
|
||||
languages_understood = [argb.language]
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
"like this is totally just a #test man",
|
||||
|
@ -3389,7 +3393,7 @@ def _command_options() -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, argb.language, conversation_id,
|
||||
low_bandwidth, argb.content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
"Zoiks!!!",
|
||||
test_save_to_file,
|
||||
|
@ -3403,7 +3407,7 @@ def _command_options() -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, argb.language, conversation_id,
|
||||
low_bandwidth, argb.content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
"Hey scoob we need like a hundred more #milkshakes",
|
||||
test_save_to_file,
|
||||
|
@ -3417,7 +3421,7 @@ def _command_options() -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, argb.language, conversation_id,
|
||||
low_bandwidth, argb.content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
"Getting kinda spooky around here",
|
||||
test_save_to_file,
|
||||
|
@ -3431,7 +3435,7 @@ def _command_options() -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, argb.language, conversation_id,
|
||||
low_bandwidth, argb.content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
"And they would have gotten away with it too" +
|
||||
"if it wasn't for those pesky hackers",
|
||||
|
@ -3446,7 +3450,7 @@ def _command_options() -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, argb.language, conversation_id,
|
||||
low_bandwidth, argb.content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
"man these centralized sites are like the worst!",
|
||||
test_save_to_file,
|
||||
|
@ -3460,7 +3464,7 @@ def _command_options() -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, argb.language, conversation_id,
|
||||
low_bandwidth, argb.content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
"another mystery solved #test",
|
||||
test_save_to_file,
|
||||
|
@ -3474,7 +3478,7 @@ def _command_options() -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, argb.language, conversation_id,
|
||||
low_bandwidth, argb.content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
"let's go bowling",
|
||||
test_save_to_file,
|
||||
|
@ -3488,7 +3492,7 @@ def _command_options() -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, argb.language, conversation_id,
|
||||
low_bandwidth, argb.content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
domain_full = domain + ':' + str(port)
|
||||
clear_follows(base_dir, nickname, domain)
|
||||
follow_person(base_dir, nickname, domain, 'maxboardroom', domain_full,
|
||||
|
|
3
inbox.py
3
inbox.py
|
@ -3745,6 +3745,7 @@ def _bounce_dm(sender_post_id: str, session, http_prefix: str,
|
|||
location = None
|
||||
conversation_id = None
|
||||
low_bandwidth = False
|
||||
buy_url = ''
|
||||
post_json_object = \
|
||||
create_direct_message_post(base_dir, nickname, domain, port,
|
||||
http_prefix, content,
|
||||
|
@ -3759,7 +3760,7 @@ def _bounce_dm(sender_post_id: str, session, http_prefix: str,
|
|||
low_bandwidth,
|
||||
content_license_url,
|
||||
languages_understood, bounce_is_chat,
|
||||
translate)
|
||||
translate, buy_url)
|
||||
if not post_json_object:
|
||||
print('WARN: unable to create bounce message to ' + sending_handle)
|
||||
return False
|
||||
|
|
|
@ -636,6 +636,7 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str,
|
|||
city = 'London, England'
|
||||
conversation_id = None
|
||||
languages_understood = [system_language]
|
||||
buy_url = ''
|
||||
blog = create_news_post(base_dir,
|
||||
domain, port, http_prefix,
|
||||
rss_description,
|
||||
|
@ -645,7 +646,8 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str,
|
|||
rss_title, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate,
|
||||
buy_url)
|
||||
if not blog:
|
||||
continue
|
||||
|
||||
|
|
80
posts.py
80
posts.py
|
@ -1092,6 +1092,27 @@ def _attach_post_license(post_json_object: {},
|
|||
})
|
||||
|
||||
|
||||
def _attach_buy_link(post_json_object: {},
|
||||
buy_url: str, translate: {}) -> None:
|
||||
"""Attaches a link for buying something
|
||||
"""
|
||||
if not buy_url:
|
||||
return
|
||||
if '://' not in buy_url:
|
||||
return
|
||||
if ' ' in buy_url or '<' in buy_url:
|
||||
return
|
||||
buy_str = 'Buy'
|
||||
if translate.get(buy_str):
|
||||
buy_str = translate[buy_str]
|
||||
post_json_object['attachment'].append({
|
||||
"type": "Link",
|
||||
"name": buy_str,
|
||||
"href": buy_url,
|
||||
"mediaType": "text/html"
|
||||
})
|
||||
|
||||
|
||||
def _create_post_s2s(base_dir: str, nickname: str, domain: str, port: int,
|
||||
http_prefix: str, content: str, status_number: str,
|
||||
published: str, new_post_id: str, post_context: {},
|
||||
|
@ -1102,7 +1123,8 @@ def _create_post_s2s(base_dir: str, nickname: str, domain: str, port: int,
|
|||
post_object_type: str, summary: str,
|
||||
in_reply_to_atom_uri: str, system_language: str,
|
||||
conversation_id: str, low_bandwidth: bool,
|
||||
content_license_url: str) -> {}:
|
||||
content_license_url: str, buy_url: str,
|
||||
translate: {}) -> {}:
|
||||
"""Creates a new server-to-server post
|
||||
"""
|
||||
actor_url = local_actor_url(http_prefix, nickname, domain)
|
||||
|
@ -1166,6 +1188,7 @@ def _create_post_s2s(base_dir: str, nickname: str, domain: str, port: int,
|
|||
media_type, image_description, city, low_bandwidth,
|
||||
content_license_url)
|
||||
_attach_post_license(new_post['object'], content_license_url)
|
||||
_attach_buy_link(new_post['object'], buy_url, translate)
|
||||
return new_post
|
||||
|
||||
|
||||
|
@ -1179,7 +1202,8 @@ def _create_post_c2s(base_dir: str, nickname: str, domain: str, port: int,
|
|||
post_object_type: str, summary: str,
|
||||
in_reply_to_atom_uri: str, system_language: str,
|
||||
conversation_id: str, low_bandwidth: str,
|
||||
content_license_url: str) -> {}:
|
||||
content_license_url: str, buy_url: str,
|
||||
translate: {}) -> {}:
|
||||
"""Creates a new client-to-server post
|
||||
"""
|
||||
domain_full = get_full_domain(domain, port)
|
||||
|
@ -1233,6 +1257,7 @@ def _create_post_c2s(base_dir: str, nickname: str, domain: str, port: int,
|
|||
media_type, image_description, city, low_bandwidth,
|
||||
content_license_url)
|
||||
_attach_post_license(new_post, content_license_url)
|
||||
_attach_buy_link(new_post, buy_url, translate)
|
||||
return new_post
|
||||
|
||||
|
||||
|
@ -1433,7 +1458,8 @@ def _create_post_base(base_dir: str,
|
|||
system_language: str,
|
||||
conversation_id: str, low_bandwidth: bool,
|
||||
content_license_url: str,
|
||||
languages_understood: [], translate: {}) -> {}:
|
||||
languages_understood: [], translate: {},
|
||||
buy_url: str) -> {}:
|
||||
"""Creates a message
|
||||
"""
|
||||
content = remove_invalid_chars(content)
|
||||
|
@ -1591,7 +1617,7 @@ def _create_post_base(base_dir: str,
|
|||
post_object_type, summary,
|
||||
in_reply_to_atom_uri, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url)
|
||||
content_license_url, buy_url, translate)
|
||||
else:
|
||||
new_post = \
|
||||
_create_post_c2s(base_dir, nickname, domain, port,
|
||||
|
@ -1604,7 +1630,7 @@ def _create_post_base(base_dir: str,
|
|||
post_object_type, summary,
|
||||
in_reply_to_atom_uri, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url)
|
||||
content_license_url, buy_url, translate)
|
||||
|
||||
_create_post_mentions(cc_url, new_post, to_recipients, tags)
|
||||
|
||||
|
@ -1845,7 +1871,8 @@ def create_public_post(base_dir: str,
|
|||
location: str, is_article: bool, system_language: str,
|
||||
conversation_id: str, low_bandwidth: bool,
|
||||
content_license_url: str,
|
||||
languages_understood: [], translate: {}) -> {}:
|
||||
languages_understood: [], translate: {},
|
||||
buy_url: str) -> {}:
|
||||
"""Public post
|
||||
"""
|
||||
domain_full = get_full_domain(domain, port)
|
||||
|
@ -1879,7 +1906,7 @@ def create_public_post(base_dir: str,
|
|||
event_status, ticket_url, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
|
||||
|
||||
def _append_citations_to_blog_post(base_dir: str,
|
||||
|
@ -1924,7 +1951,8 @@ def create_blog_post(base_dir: str,
|
|||
location: str, system_language: str,
|
||||
conversation_id: str, low_bandwidth: bool,
|
||||
content_license_url: str,
|
||||
languages_understood: [], translate: {}) -> {}:
|
||||
languages_understood: [], translate: {},
|
||||
buy_url: str) -> {}:
|
||||
blog_json = \
|
||||
create_public_post(base_dir,
|
||||
nickname, domain, port, http_prefix,
|
||||
|
@ -1937,7 +1965,7 @@ def create_blog_post(base_dir: str,
|
|||
event_date, event_time, event_end_time, location,
|
||||
True, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
blog_json['object']['url'] = \
|
||||
blog_json['object']['url'].replace('/@', '/users/')
|
||||
_append_citations_to_blog_post(base_dir, nickname, domain, blog_json)
|
||||
|
@ -1953,7 +1981,8 @@ def create_news_post(base_dir: str,
|
|||
subject: str, system_language: str,
|
||||
conversation_id: str, low_bandwidth: bool,
|
||||
content_license_url: str,
|
||||
languages_understood: [], translate: {}) -> {}:
|
||||
languages_understood: [], translate: {},
|
||||
buy_url: str) -> {}:
|
||||
client_to_server = False
|
||||
in_reply_to = None
|
||||
in_reply_to_atom_uri = None
|
||||
|
@ -1974,7 +2003,7 @@ def create_news_post(base_dir: str,
|
|||
event_date, event_time, event_end_time, location,
|
||||
True, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
blog['object']['type'] = 'Article'
|
||||
return blog
|
||||
|
||||
|
@ -1995,6 +2024,7 @@ def create_question_post(base_dir: str,
|
|||
"""
|
||||
domain_full = get_full_domain(domain, port)
|
||||
local_actor = local_actor_url(http_prefix, nickname, domain_full)
|
||||
buy_url = ''
|
||||
message_json = \
|
||||
_create_post_base(base_dir, nickname, domain, port,
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
|
@ -2008,7 +2038,7 @@ def create_question_post(base_dir: str,
|
|||
None, None, None,
|
||||
None, None, None, None, None, system_language,
|
||||
None, low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
message_json['object']['type'] = 'Question'
|
||||
message_json['object']['oneOf'] = []
|
||||
message_json['object']['votersCount'] = 0
|
||||
|
@ -2043,7 +2073,8 @@ def create_unlisted_post(base_dir: str,
|
|||
location: str, system_language: str,
|
||||
conversation_id: str, low_bandwidth: bool,
|
||||
content_license_url: str,
|
||||
languages_understood: [], translate: {}) -> {}:
|
||||
languages_understood: [], translate: {},
|
||||
buy_url: str) -> {}:
|
||||
"""Unlisted post. This has the #Public and followers links inverted.
|
||||
"""
|
||||
domain_full = get_full_domain(domain, port)
|
||||
|
@ -2063,7 +2094,7 @@ def create_unlisted_post(base_dir: str,
|
|||
None, None, None, None, None, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url, languages_understood,
|
||||
translate)
|
||||
translate, buy_url)
|
||||
|
||||
|
||||
def create_followers_only_post(base_dir: str,
|
||||
|
@ -2082,7 +2113,7 @@ def create_followers_only_post(base_dir: str,
|
|||
conversation_id: str, low_bandwidth: bool,
|
||||
content_license_url: str,
|
||||
languages_understood: [],
|
||||
translate: {}) -> {}:
|
||||
translate: {}, buy_url: str) -> {}:
|
||||
"""Followers only post
|
||||
"""
|
||||
domain_full = get_full_domain(domain, port)
|
||||
|
@ -2100,7 +2131,7 @@ def create_followers_only_post(base_dir: str,
|
|||
None, None, None, None, None, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url, languages_understood,
|
||||
translate)
|
||||
translate, buy_url)
|
||||
|
||||
|
||||
def get_mentioned_people(base_dir: str, http_prefix: str,
|
||||
|
@ -2157,7 +2188,8 @@ def create_direct_message_post(base_dir: str,
|
|||
conversation_id: str, low_bandwidth: bool,
|
||||
content_license_url: str,
|
||||
languages_understood: [],
|
||||
dm_is_chat: bool, translate: {}) -> {}:
|
||||
dm_is_chat: bool, translate: {},
|
||||
buy_url: str) -> {}:
|
||||
"""Direct Message post
|
||||
"""
|
||||
content = resolve_petnames(base_dir, nickname, domain, content)
|
||||
|
@ -2183,7 +2215,7 @@ def create_direct_message_post(base_dir: str,
|
|||
None, None, None, None, None, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url, languages_understood,
|
||||
translate)
|
||||
translate, buy_url)
|
||||
# mentioned recipients go into To rather than Cc
|
||||
message_json['to'] = message_json['object']['cc']
|
||||
message_json['object']['to'] = message_json['to']
|
||||
|
@ -2269,11 +2301,11 @@ def create_report_post(base_dir: str,
|
|||
post_to = moderators_list
|
||||
post_cc = None
|
||||
post_json_object = None
|
||||
buy_url = ''
|
||||
for to_url in post_to:
|
||||
# who is this report going to?
|
||||
to_nickname = to_url.split('/users/')[1]
|
||||
handle = to_nickname + '@' + domain
|
||||
|
||||
post_json_object = \
|
||||
_create_post_base(base_dir, nickname, domain, port,
|
||||
to_url, post_cc,
|
||||
|
@ -2286,7 +2318,7 @@ def create_report_post(base_dir: str,
|
|||
None, None, None,
|
||||
None, None, None, None, None, system_language,
|
||||
None, low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
if not post_json_object:
|
||||
continue
|
||||
|
||||
|
@ -2411,7 +2443,7 @@ def send_post(signing_priv_key_pem: str, project_version: str,
|
|||
shared_items_federated_domains: [],
|
||||
shared_item_federation_tokens: {},
|
||||
low_bandwidth: bool, content_license_url: str,
|
||||
translate: {},
|
||||
translate: {}, buy_url: str,
|
||||
debug: bool = False, in_reply_to: str = None,
|
||||
in_reply_to_atom_uri: str = None, subject: str = None) -> int:
|
||||
"""Post to another inbox. Used by unit tests.
|
||||
|
@ -2479,7 +2511,7 @@ def send_post(signing_priv_key_pem: str, project_version: str,
|
|||
None, None, None, None, None, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url, languages_understood,
|
||||
translate)
|
||||
translate, buy_url)
|
||||
|
||||
# get the senders private key
|
||||
private_key_pem = get_person_key(nickname, domain, base_dir, 'private')
|
||||
|
@ -2576,7 +2608,7 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str,
|
|||
low_bandwidth: bool,
|
||||
content_license_url: str,
|
||||
event_date: str, event_time: str, event_end_time: str,
|
||||
location: str, translate: {},
|
||||
location: str, translate: {}, buy_url: str,
|
||||
debug: bool = False,
|
||||
in_reply_to: str = None,
|
||||
in_reply_to_atom_uri: str = None,
|
||||
|
@ -2668,7 +2700,7 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str,
|
|||
None, None, None, None, None, system_language,
|
||||
conversation_id, low_bandwidth,
|
||||
content_license_url, languages_understood,
|
||||
translate)
|
||||
translate, buy_url)
|
||||
|
||||
auth_header = create_basic_auth_header(from_nickname, password)
|
||||
|
||||
|
|
47
tests.py
47
tests.py
|
@ -773,6 +773,7 @@ def create_server_alice(path: str, domain: str, port: int,
|
|||
conversation_id = None
|
||||
translate = {}
|
||||
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
|
||||
buy_url = ''
|
||||
create_public_post(path, nickname, domain, port, http_prefix,
|
||||
"No wise fish would go anywhere without a porpoise",
|
||||
test_save_to_file,
|
||||
|
@ -787,7 +788,7 @@ def create_server_alice(path: str, domain: str, port: int,
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(path, nickname, domain, port, http_prefix,
|
||||
"Curiouser and curiouser!",
|
||||
test_save_to_file,
|
||||
|
@ -802,7 +803,7 @@ def create_server_alice(path: str, domain: str, port: int,
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(path, nickname, domain, port, http_prefix,
|
||||
"In the gardens of memory, in the palace " +
|
||||
"of dreams, that is where you and I shall meet",
|
||||
|
@ -818,7 +819,7 @@ def create_server_alice(path: str, domain: str, port: int,
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
regenerate_index_for_box(path, nickname, domain, 'outbox')
|
||||
global TEST_SERVER_ALICE_RUNNING
|
||||
TEST_SERVER_ALICE_RUNNING = True
|
||||
|
@ -937,6 +938,7 @@ def create_server_bob(path: str, domain: str, port: int,
|
|||
conversation_id = None
|
||||
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
create_public_post(path, nickname, domain, port, http_prefix,
|
||||
"It's your life, live it your way.",
|
||||
test_save_to_file,
|
||||
|
@ -951,7 +953,7 @@ def create_server_bob(path: str, domain: str, port: int,
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(path, nickname, domain, port, http_prefix,
|
||||
"One of the things I've realised is that " +
|
||||
"I am very simple",
|
||||
|
@ -967,7 +969,7 @@ def create_server_bob(path: str, domain: str, port: int,
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
create_public_post(path, nickname, domain, port, http_prefix,
|
||||
"Quantum physics is a bit of a passion of mine",
|
||||
test_save_to_file,
|
||||
|
@ -982,7 +984,7 @@ def create_server_bob(path: str, domain: str, port: int,
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
regenerate_index_for_box(path, nickname, domain, 'outbox')
|
||||
global TEST_SERVER_BOB_RUNNING
|
||||
TEST_SERVER_BOB_RUNNING = True
|
||||
|
@ -1321,6 +1323,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
|||
low_bandwidth = False
|
||||
signing_priv_key_pem = None
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
send_result = \
|
||||
send_post(signing_priv_key_pem, __version__,
|
||||
session_alice, alice_dir, 'alice', alice_domain, alice_port,
|
||||
|
@ -1335,7 +1338,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
|||
languages_understood,
|
||||
alice_shared_items_federated_domains,
|
||||
alice_shared_item_federation_tokens, low_bandwidth,
|
||||
content_license_url, translate,
|
||||
content_license_url, translate, buy_url,
|
||||
in_reply_to, in_reply_to_atom_uri, subject)
|
||||
print('send_result: ' + str(send_result))
|
||||
|
||||
|
@ -1402,6 +1405,8 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
|||
assert 'यह एक परीक्षण है' in received_json['object']['content']
|
||||
print('Check that message received from Alice contains an attachment')
|
||||
assert received_json['object']['attachment']
|
||||
if len(received_json['object']['attachment']) != 2:
|
||||
pprint(received_json['object']['attachment'])
|
||||
assert len(received_json['object']['attachment']) == 2
|
||||
attached = received_json['object']['attachment'][0]
|
||||
pprint(attached)
|
||||
|
@ -1693,6 +1698,7 @@ def test_follow_between_servers(base_dir: str) -> None:
|
|||
low_bandwidth = False
|
||||
signing_priv_key_pem = None
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
send_result = \
|
||||
send_post(signing_priv_key_pem, __version__,
|
||||
session_alice, alice_dir, 'alice', alice_domain, alice_port,
|
||||
|
@ -1705,7 +1711,7 @@ def test_follow_between_servers(base_dir: str) -> None:
|
|||
languages_understood,
|
||||
alice_shared_items_federated_domains,
|
||||
alice_shared_item_federation_tokens, low_bandwidth,
|
||||
content_license_url, translate,
|
||||
content_license_url, translate, buy_url,
|
||||
in_reply_to, in_reply_to_atom_uri, subject)
|
||||
print('send_result: ' + str(send_result))
|
||||
|
||||
|
@ -2060,6 +2066,7 @@ def test_shared_items_federation(base_dir: str) -> None:
|
|||
low_bandwidth = False
|
||||
signing_priv_key_pem = None
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
send_result = \
|
||||
send_post(signing_priv_key_pem, __version__,
|
||||
session_alice, alice_dir, 'alice', alice_domain, alice_port,
|
||||
|
@ -2072,7 +2079,7 @@ def test_shared_items_federation(base_dir: str) -> None:
|
|||
languages_understood,
|
||||
alice_shared_items_federated_domains,
|
||||
alice_shared_item_federation_tokens, low_bandwidth,
|
||||
content_license_url, translate, True,
|
||||
content_license_url, translate, buy_url, True,
|
||||
in_reply_to, in_reply_to_atom_uri, subject)
|
||||
print('send_result: ' + str(send_result))
|
||||
|
||||
|
@ -2490,6 +2497,7 @@ def test_group_follow(base_dir: str) -> None:
|
|||
if os.path.isfile(os.path.join(outbox_path, name))])
|
||||
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
send_result = \
|
||||
send_post(signing_priv_key_pem, __version__,
|
||||
session_alice, alice_dir, 'alice', alice_domain, alice_port,
|
||||
|
@ -2502,7 +2510,7 @@ def test_group_follow(base_dir: str) -> None:
|
|||
languages_understood,
|
||||
alice_shared_items_federated_domains,
|
||||
alice_shared_item_federation_tokens, low_bandwidth,
|
||||
content_license_url, translate,
|
||||
content_license_url, translate, buy_url,
|
||||
in_reply_to, in_reply_to_atom_uri, subject)
|
||||
print('send_result: ' + str(send_result))
|
||||
|
||||
|
@ -2877,6 +2885,7 @@ def _test_create_person_account(base_dir: str):
|
|||
"(yawn)\n\n...then it's not really independent.\n\n" + \
|
||||
"Politicians will threaten to withdraw funding if you do " + \
|
||||
"anything which challenges middle class sensibilities or incomes."
|
||||
buy_url = ''
|
||||
test_post_json = \
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
content, save_to_file,
|
||||
|
@ -2889,7 +2898,7 @@ def _test_create_person_account(base_dir: str):
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
assert test_post_json
|
||||
assert test_post_json.get('object')
|
||||
assert test_post_json['object']['content']
|
||||
|
@ -2915,7 +2924,7 @@ def _test_create_person_account(base_dir: str):
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
assert test_post_json
|
||||
assert test_post_json.get('object')
|
||||
assert test_post_json['object']['content']
|
||||
|
@ -3116,6 +3125,7 @@ def test_client_to_server(base_dir: str):
|
|||
event_end_time = '12:30'
|
||||
location = "Kinshasa"
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
send_result = \
|
||||
send_post_via_server(signing_priv_key_pem, __version__,
|
||||
alice_dir, session_alice, 'alice', password,
|
||||
|
@ -3128,7 +3138,7 @@ def test_client_to_server(base_dir: str):
|
|||
system_language, languages_understood,
|
||||
low_bandwidth, content_license_url,
|
||||
event_date, event_time, event_end_time, location,
|
||||
translate, True, None, None,
|
||||
translate, buy_url, True, None, None,
|
||||
conversation_id, None)
|
||||
print('send_result: ' + str(send_result))
|
||||
|
||||
|
@ -4728,6 +4738,7 @@ def _test_reply_to_public_post(base_dir: str) -> None:
|
|||
low_bandwidth = True
|
||||
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
reply = \
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
content, save_to_file,
|
||||
|
@ -4740,7 +4751,7 @@ def _test_reply_to_public_post(base_dir: str) -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
# print(str(reply))
|
||||
expected_str = \
|
||||
'<p><span class=\"h-card\">' + \
|
||||
|
@ -5678,6 +5689,7 @@ def _test_links_within_post(base_dir: str) -> None:
|
|||
low_bandwidth = True
|
||||
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
|
||||
post_json_object = \
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
|
@ -5691,7 +5703,7 @@ def _test_links_within_post(base_dir: str) -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
|
||||
expected_str = \
|
||||
'<p>This is a test post with links.<br><br>' + \
|
||||
|
@ -5735,7 +5747,7 @@ def _test_links_within_post(base_dir: str) -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
assert post_json_object['object']['content'] == content
|
||||
assert post_json_object['object']['contentMap'][system_language] == content
|
||||
|
||||
|
@ -6787,6 +6799,7 @@ def _test_can_replyto(base_dir: str) -> None:
|
|||
low_bandwidth = True
|
||||
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
|
||||
translate = {}
|
||||
buy_url = ''
|
||||
|
||||
post_json_object = \
|
||||
create_public_post(base_dir, nickname, domain, port, http_prefix,
|
||||
|
@ -6800,7 +6813,7 @@ def _test_can_replyto(base_dir: str) -> None:
|
|||
test_event_end_time, test_location,
|
||||
test_is_article, system_language, conversation_id,
|
||||
low_bandwidth, content_license_url,
|
||||
languages_understood, translate)
|
||||
languages_understood, translate, buy_url)
|
||||
# set the date on the post
|
||||
curr_date_str = "2021-09-08T20:45:00Z"
|
||||
post_json_object['published'] = curr_date_str
|
||||
|
|
|
@ -776,7 +776,7 @@ def html_new_post(edit_post_params: {},
|
|||
translate['Language used'] + '</label>\n'
|
||||
replies_section += languages_dropdown
|
||||
buy_link_str = '🛒 ' + translate['Buy link']
|
||||
replies_section += edit_text_field(buy_link_str, 'buySite',
|
||||
replies_section += edit_text_field(buy_link_str, 'buyUrl',
|
||||
default_buy_site, 'https://...')
|
||||
replies_section += '</div>\n'
|
||||
|
||||
|
|
|
@ -2091,9 +2091,10 @@ def get_buy_links(post_json_object: str, translate: {}, buy_sites: {}) -> {}:
|
|||
return {}
|
||||
links = {}
|
||||
buy_strings = []
|
||||
buy_strings += translate['Buy'].lower()
|
||||
buy_strings += translate['Purchase'].lower()
|
||||
buy_strings += translate['Subscribe'].lower()
|
||||
for buy_str in ('Buy', 'Purchase', 'Subscribe'):
|
||||
if translate.get(buy_str):
|
||||
buy_str = translate[buy_str]
|
||||
buy_strings += buy_str.lower()
|
||||
for item in post_json_object['object']['tag']:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue