Algorithmifying mastodon
Project description
mastotron
Experiments in algorithmifying mastodon
Use as webserver
# Clone repo
git clone https://github.com/quadrismegistus/mastotron.git
# move into folder
cd mastotron
# start a virtual environment
python -m venv venv
. venv/bin/activate
# install requirements
pip install -r requirements.txt
# run flask
flask --debug run
Use in jupyter/python
# load the class
from mastotron import Mastotron, Post
# instantiate; will guide through auth
tron = Mastotron()
# get latest post
post = tron.latest_post()
post
ingridbmason@ausglam.space (382 👥) reposted at 12/24/2022 at 10:23:22:
acb@mastodon.social (379 👥) wrote on 12/24/2022 at 08:54:51:
RT @luismbat@birbsite
Who would have thought that adding a Sierpinski Triangle Fractal as musical notes would actually sound good!😅
3 🗣 | 25 🔁 | 0 💙 | Post ID: 109567809382202427
# Get a post by id on your server
post = Post(id=109566222383974657)
post
RebeccaRHelm@mstdn.science (1,157 👥) wrote on 12/24/2022 at 02:11:04:
EXTREMELY RARE footage of the elusive box jellyfish Chirodectes. Larger than a soccer ball, this jelly is a true ocean mystery, and this video is one of the only in existence, filmed off the coast of Papua New Guinea in 2021.
📽️Scuba Ventures Kavieng bit.ly/3FE29tL
11 🗣 | 77 🔁 | 4 💙 | Post ID: 109566222383974657
# These will show reposts/boosts:
post = Post(id=109565672404848243)
post
accommodatingly (287 👥) reposted at 12/23/2022 at 23:51:23:
esther@strangeobject.space (1,367 👥) wrote on 12/23/2022 at 14:42:00:
Thinking of all the queer folks who have to spend the holidays with abusive, unaccepting, unsupportive, or “well meaning” but careless relatives. It’s an especially dark time for many who can’t escape those situations because they’re minors, financially dependent, or under emotional pressure to attend.
If you’re out there, struggling, and need a friendly voice, feel free to drop a DM. I’m happy to be your trans goth aunt for a bit.
#queer #trans #holidays #support
12 🗣 | 60 🔁 | 4 💙 | Post ID: 109563512620764058
# the post and boosted post
post, post.is_boost_of
(Post(id=109565672404848243), Post(id=109563512620764058))
# And replies
post = Post(id=109564529870067074)
post
heuser (235 👥) wrote on 12/23/2022 at 19:00:50:
Unexpected challenge: there are very few likes on tweets in my mastodon timeline. (step that up pls everyone thx.) So it's hard to sort the tweets using that metric.
1 🗣 | 0 🔁 | 2 💙 | Post ID: 109564529870067074
... in reply to:
heuser (235 👥) wrote on 12/23/2022 at 18:42:58:
Experimenting with making an "algorithm" to sort a user's feed using python and mastodon.py. This tweet was sent from a jupyter notebook.
1 🗣 | 1 🔁 | 3 💙 | Post ID: 109564459673004810
# the replied-to post
post, post.is_reply_to
(Post(id=109564529870067074), Post(id=109564459673004810))
# these can be chained
Post(id=109564658606466762).is_reply_to.is_reply_to.is_reply_to.id == post.id
True
Scoring posts
# Get scores for a post
# (adapted from https://github.com/hodgesmr/mastodon_digest)
post.scores()
{'Simple': 1.7320508075688774,
'ExtendedSimple': 1.8171205928321397,
'SimpleWeighted': 0.11274690420042434,
'ExtendedSimpleWeighted': 0.11828447555082267,
'All': 0.4526308886948211}
# Get top posts by score
top_posts = sorted(
tron.latest_posts(max_posts=100),
key=lambda post: -post.score()
)
# top post by engagement
top_posts[0]
ecourtem (346 👥) reposted at 12/23/2022 at 14:53:21:
lolennui@mstdn.social (5,061 👥) wrote on 12/23/2022 at 02:36:55:
Every gen X person read a terrifying Stephen King book when they were 9
55 🗣 | 33 🔁 | 1 💙 | Post ID: 109560661039545409
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.