refactor AP Note stringifying out to ap_utils.py
This commit is contained in:
parent
b8adb6f52d
commit
55d5692856
2 changed files with 27 additions and 34 deletions
|
@ -74,37 +74,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
if not items:
|
if not items:
|
||||||
raise utils.EventError("No toots found")
|
raise utils.EventError("No toots found")
|
||||||
|
|
||||||
first_item = items[0]
|
out, url = ap_utils.format_note(actor, items[0])
|
||||||
if first_item["type"] == "Announce":
|
shorturl = self.exports.get_one("shorturl")(event["server"], url,
|
||||||
retoot_url = first_item["object"]
|
context=event["target"])
|
||||||
retoot_instance = urllib.parse.urlparse(retoot_url).hostname
|
out = "%s - %s" % (out, shorturl)
|
||||||
retoot = utils.http.request(retoot_url,
|
event["stdout"].write(out)
|
||||||
headers=ACTIVITY_HEADERS, json=True, useragent=USERAGENT)
|
|
||||||
|
|
||||||
original_tooter = ap_actor.Actor(retoot.data["attributedTo"])
|
|
||||||
original_tooter.load()
|
|
||||||
|
|
||||||
original_tooter = utils.http.request(original_tooter_url,
|
|
||||||
headers=ACTIVITY_HEADERS, json=True, useragent=USERAGENT)
|
|
||||||
|
|
||||||
retooted_user = "@%s@%s" % (original_tooter.username,
|
|
||||||
retoot_instance)
|
|
||||||
|
|
||||||
shorturl = self.exports.get_one("shorturl")(
|
|
||||||
event["server"], retoot_url)
|
|
||||||
retoot_content = utils.http.strip_html(
|
|
||||||
retoot.data["content"])
|
|
||||||
|
|
||||||
event["stdout"].write("%s (boost %s): %s - %s" % (
|
|
||||||
actor.username, retooted_user, retoot_content,
|
|
||||||
shorturl))
|
|
||||||
|
|
||||||
elif first_item["type"] == "Create":
|
|
||||||
content = utils.http.strip_html(
|
|
||||||
first_item["object"]["content"])
|
|
||||||
url = first_item["object"]["id"]
|
|
||||||
shorturl = self.exports.get_one("shorturl")(
|
|
||||||
event["server"], url)
|
|
||||||
|
|
||||||
event["stdout"].write("%s: %s - %s" % (actor.username,
|
|
||||||
content, shorturl))
|
|
||||||
|
|
|
@ -54,3 +54,25 @@ def find_actor(username, instance):
|
||||||
if link["type"] == ACTIVITY_TYPE:
|
if link["type"] == ACTIVITY_TYPE:
|
||||||
return link["href"]
|
return link["href"]
|
||||||
|
|
||||||
|
def format_note(actor, note):
|
||||||
|
if note["type"] == "Announce":
|
||||||
|
retoot_url = note["object"]
|
||||||
|
retoot_instance = urllib.parse.urlparse(retoot_url).hostname
|
||||||
|
retoot = activity_request(retoot_url)
|
||||||
|
|
||||||
|
original_tooter = ap_actor.Actor(retoot.data["attributedTo"])
|
||||||
|
original_tooter.load()
|
||||||
|
original_tooter = activity_request(original_tooter_url)
|
||||||
|
retooted_user = "@%s@%s" % (original_tooter.username, retoot_instance)
|
||||||
|
retoot_content = utils.http.strip_html(retoot.data["content"])
|
||||||
|
|
||||||
|
return "%s (boost %s): %s - %s" % (
|
||||||
|
actor.username, retooted_user, retoot_content), retoot_url
|
||||||
|
|
||||||
|
elif note["type"] == "Create":
|
||||||
|
content = utils.http.strip_html(note["object"]["content"])
|
||||||
|
url = note["object"]["id"]
|
||||||
|
|
||||||
|
return "%s: %s" % (actor.username, content), url
|
||||||
|
|
||||||
|
return None, None
|
||||||
|
|
Loading…
Reference in a new issue