Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Conversation

@georgedorn
Copy link
Contributor

@georgedorn georgedorn commented Dec 2, 2017

I found your project today when searching again for an app that read Mastodon and outputted RSS; I've specifically been looking for a way to generate an RSS feed of my favorites, so I added that.

Along the way, I fixed a couple of bugs in a backwards-compatible way:

  • toot['created_at'] is already a datetime in the current version of Mastodon.py
  • it also already has a timezone.

Creating a mastodon app and credentials is non-trivial, especially for users of instances other than the flagship. After figuring the process out, I wrote a simple script (create_mastodon_client.py) to simplify the process; it relies on values in config.yml so I updated the README accordingly.

Feel free to ignore this; I'm just sending you this PR as a courtesy and a thank-you for implementing 95% of what I wanted.

import sys

import os
from config import get_config
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the config loading here so I could use it in create_mastodon_client.


# Mastodon
try:
client_file = param['mastodon']['client_id_file']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some sanity checks here because I had a typo in my config file that was tricky to debug.

access_token=param['mastodon']['access_token_file']
client_id=client_file,
access_token=access_token_file,
api_base_url=mastodon_url
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this after discovering it refused to work for anything but the flagship instance.

'✰ : ' + str(toot['favourites_count']) + '</div></blockquote>'

toot['created_at'] = datetime.datetime.strptime(toot['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ')
if isinstance(toot['created_at'], str):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the most recent Mastodon.py, created_at is already a datetime, so this conversion is only needed with older versions of the client.


text = BeautifulSoup(toot['content'], "html.parser").text
pubdate = toot['created_at']
if not pubdate.tzinfo:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, the created_at datetime already has timezone info. I'm not entirely sure which timezone is used, but I suspect it is whatever my user account's preference is set to.


if __name__ == "__main__":
app.run()
app.run(use_reloader=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was helpful during dev. I haven't deployed it, but I suspect it won't have any effect under gunicorn or whatever.

password = getpass("Password (not shown and not saved):")

# Log in - either every time, or use persisted
mastodon.log_in(user_email, password, to_file=mast_cfg['access_token_file'], scopes=['read'])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This app doesn't need write or follow permissions, so this asks only for read access. It looks a little less scary on the authorized apps page...

return xml

@app.route('/toot_favorites')
def toot_favorites_feed():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this was what started me on this whole thing.

@SamR1 SamR1 merged commit 0c7e187 into SamR1:master Dec 7, 2017
@SamR1
Copy link
Owner

SamR1 commented Dec 7, 2017

thanks again @georgedorn 👍

Repository owner locked and limited conversation to collaborators Dec 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants