kopia lustrzana https://codeberg.org/edent/Mastodon_Tools
Better formatting
rodzic
35c8f19828
commit
bae75de1e5
|
@ -1,12 +1,13 @@
|
|||
from datetime import datetime, timedelta
|
||||
from mastodon import Mastodon
|
||||
from treelib import Node, Tree
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
import config
|
||||
|
||||
# Status ID
|
||||
# This is the ID from *your* instance
|
||||
status_id = 109343943300929632
|
||||
status_id = 109343943300929632
|
||||
|
||||
# Set up access
|
||||
mastodon = Mastodon( api_base_url=config.instance, access_token=config.access_token )
|
||||
|
@ -31,14 +32,14 @@ tree = Tree()
|
|||
# Add the "root"
|
||||
try :
|
||||
tree.create_node(
|
||||
str(status["created_at"]) + " " + status["account"]["username"] + " " + status["uri"], status["id"])
|
||||
str(status["created_at"])[:16] + " " + status["account"]["username"] + ": " + BeautifulSoup(status["content"], features="html.parser").get_text() + " " + 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"])
|
||||
tree.create_node(str(status["created_at"])[:16] + " " + status["account"]["username"] + ": " + BeautifulSoup(status["content"], features="html.parser").get_text() + " " + status["uri"], status["id"], parent=status["in_reply_to_id"])
|
||||
except :
|
||||
# If a parent node is missing
|
||||
print("Problem adding node to the tree")
|
||||
|
|
Ładowanie…
Reference in New Issue