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