iframeable display of all posts by a matodon @user@instance account that contain a #hashtag
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mymastotag.py 1.3KB

123456789101112131415161718192021222324252627282930313233
  1. import time
  2. import feedparser
  3. from flask import Flask, render_template
  4. from bs4 import BeautifulSoup
  5. application = Flask(__name__)
  6. @application.route('/<string:lang>/<string:instance>/<string:user>/<string:tag>')
  7. def my_masto_tag(lang, instance, user, tag):
  8. lang = lang.lower()
  9. is_rtl = lang in ['he', 'ar'] # TODO: A less lame to determine rtl
  10. title = f'@{user}@{instance} &mdash; #{tag}'
  11. feed = feedparser.parse(f'https://{instance}/@{user}/tagged/{tag}.rss')
  12. for e in feed['entries']:
  13. e['date'] = time.strftime('%Y-%m-%d', e['published_parsed'])
  14. soup = BeautifulSoup(e['description'], 'html.parser')
  15. for link in soup.find_all('a'):
  16. link['target'] = '_blank'
  17. link['class'] = ['link-info', 'text-decoration-none']
  18. e['description'] = str(soup)
  19. images = []
  20. videos =[]
  21. for m in e['media_content']:
  22. mtype = m['type'].split('/')[0]
  23. if mtype=='image':
  24. images.append(m)
  25. elif mtype=='video':
  26. videos.append(m)
  27. e['images'] = images
  28. e['has_images'] = not not images
  29. e['videos'] = videos
  30. e['has_videos'] = not not videos
  31. return render_template('index.html', lang=lang, is_rtl=is_rtl, title=title, feed=feed)