husimo/twootfeed

A simple python alpine container configured to run twootfeed script.

You just have to set your parameters in docker-compose.yml :

version: "3"
services:
  twootfeed:
    build: .
    ports:
      # You can change to "1234:5000" if you don't want to use 5000.
      - "5000:5000"
    environment:
      # URL of your mastodon instance
      - API_BASE_URL=https://mamot.fr
      # Email used by your account
      - EMAIL=xxxx
      # Password
      - PASSWORD=xxxx

Then, launch your container :

$ docker-compose up -d

python-twootfeed

Python script to generate a rss feed from parsed Twitter or Mastodon search, using Flask.

The RSS feed displays only the original tweets (not the retweets) and :

  • links to :
    -- the original tweet on Twitter or toot on Mastodon -- hashtags
    -- usernames
  • URLs
  • images (only for Twitter for now)
  • source (only for Twitter for now)
  • location (only for Twitter)
  • numbers of retweets (or reblogs for Mastodon) and favorites
    (see examples below).

Codacy Badge

Requirements :

Steps :

  • install Python packages : flask, BeautifulSoup, Mastodon.py, feedgenerator, tweepy and pytz
$ pip3 install flask bs4 feedgenerator tweepy pytz Mastodon.py
  • clone this repo :
$ git clone https://github.com/SamR1/python-twootfeed.git
  • API Keys
    • for Twitter : see https://dev.twitter.com
      copy/paste the Twitter API key values in config.yml.example ('consumerKey' and 'consumerSecret')
    • for Mastodon : see Python wrapper for the Mastodon API
      • generate client and user credentials files :
      from mastodon import Mastodon
      
      # Register app - only once!        
      Mastodon.create_app(
           'pytooterapp',
            to_file = 'tootrss_clientcred.txt'
      )        
      
      # Log in - either every time, or use persisted        
      mastodon = Mastodon(client_id = 'tootrss_clientcred.txt')
      mastodon.log_in(
          'my_login_email@example.com',
          'incrediblygoodpassword',
          to_file = 'tootrss_usercred.txt'
      )
      • copy/paste file names in config.yml.example ('client_id_file' and 'access_token_file')

Rename the config file config.yml.

  • Start the server
$ export FLASK_APP=app.py
$ python3 -m flask run --host=0.0.0.0

Examples :

Search on Twitter :

Twitter search

Results in RSS Feed :
RSS Feed

Display on FreshRSS, a great free self-hosted aggregator (https://github.com/FreshRSS/FreshRSS):
FreshRSS

Search on Mastodon :

Mastodon search

Results in RSS Feed :
Mastodon Feed

Display on FreshRSS : Mastodon FreshRSS

Todo :

  • handle the tweeperror "Rate limit exceeded" #2
  • handle the different exceptions properly