import time import feedparser from flask import Flask, render_template from bs4 import BeautifulSoup application = Flask(__name__) @application.route('////') def my_masto_tag(lang, instance, user, tag): lang = lang.lower() is_rtl = lang in ['he', 'ar'] # TODO: A less lame to determine rtl title = f'@{user}@{instance} — #{tag}' feed = feedparser.parse(f'https://{instance}/@{user}/tagged/{tag}.rss') for e in feed['entries']: e['date'] = time.strftime('%Y-%m-%d', e['published_parsed']) soup = BeautifulSoup(e['description'], 'html.parser') for link in soup.find_all('a'): link['target'] = '_blank' link['class'] = ['link-info', 'text-decoration-none'] e['description'] = str(soup) images = [] videos =[] for m in e['media_content']: mtype = m['type'].split('/')[0] if mtype=='image': images.append(m) elif mtype=='video': videos.append(m) e['images'] = images e['has_images'] = not not images e['videos'] = videos e['has_videos'] = not not videos return render_template('index.html', lang=lang, is_rtl=is_rtl, title=title, feed=feed)