kopia lustrzana https://codeberg.org/edent/Mastodon_Tools
Added Thread viewer
rodzic
79db10c94c
commit
39052559b3
|
@ -4,7 +4,6 @@ from mastodon import Mastodon
|
|||
import config
|
||||
|
||||
# Set up access
|
||||
instance = "https://mastodon.example"
|
||||
mastodon = Mastodon( api_base_url=config.instance, access_token=config.access_token )
|
||||
|
||||
# Get user's info
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
from datetime import datetime, timedelta
|
||||
from mastodon import Mastodon
|
||||
from treelib import Node, Tree
|
||||
|
||||
import config
|
||||
|
||||
# Status ID
|
||||
# This is the ID from *your* instance
|
||||
status_id = 109343943300929632
|
||||
|
||||
# Set up access
|
||||
mastodon = Mastodon( api_base_url=config.instance, access_token=config.access_token )
|
||||
|
||||
# Get the status
|
||||
status = mastodon.status(status_id)
|
||||
|
||||
# Get the conversation tree
|
||||
# Documentation https://docs.joinmastodon.org/entities/context/
|
||||
conversation = mastodon.status_context(status_id)
|
||||
|
||||
# If there are ancestors, that means we are only on a single branch.
|
||||
# The 0th ancestor is the "root" of the conversation tree
|
||||
if len(conversation["ancestors"]) > 0 :
|
||||
status = conversation["ancestors"][0]
|
||||
status_id = status["id"]
|
||||
conversation = mastodon.status_context(status_id)
|
||||
|
||||
# Create a new tree
|
||||
tree = Tree()
|
||||
|
||||
# Add the "root"
|
||||
try :
|
||||
tree.create_node(
|
||||
str(status["created_at"]) + " " + status["account"]["username"] + " " + status["uri"], status["id"])
|
||||
except :
|
||||
print("Problem adding node to the tree")
|
||||
|
||||
# Add any subsequent replies
|
||||
for status in conversation["descendants"] :
|
||||
try :
|
||||
tree.create_node(str(status["created_at"]) + " " + status["account"]["username"] + " " + status["uri"], status["id"], parent=status["in_reply_to_id"])
|
||||
except :
|
||||
# If a parent node is missing
|
||||
print("Problem adding node to the tree")
|
||||
|
||||
# Display
|
||||
tree.show()
|
Ładowanie…
Reference in New Issue