瀏覽代碼

Highlight links to topic tag

master
The Dod 1 年之前
父節點
當前提交
524ba6c550
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5
    1
      mymastotag.py

+ 5
- 1
mymastotag.py 查看文件

19
     title = f'@{user}@{instance} — #{tag}'
19
     title = f'@{user}@{instance} — #{tag}'
20
     og_image = None
20
     og_image = None
21
     feed = feedparser.parse(f'https://{instance}/@{user}/tagged/{tag}.rss')
21
     feed = feedparser.parse(f'https://{instance}/@{user}/tagged/{tag}.rss')
22
+    hashtag = '#' + tag.lower()
22
     for e in feed['entries']:
23
     for e in feed['entries']:
23
         e['date'] = time.strftime('%Y-%m-%d', e['published_parsed'])
24
         e['date'] = time.strftime('%Y-%m-%d', e['published_parsed'])
24
         soup = BeautifulSoup(e['description'], 'html.parser')
25
         soup = BeautifulSoup(e['description'], 'html.parser')
25
         for link in soup.find_all('a'):
26
         for link in soup.find_all('a'):
26
             link['target'] = '_blank'
27
             link['target'] = '_blank'
27
-            link['class'] = ['link-info', 'text-decoration-none']
28
+            if link.text.lower()==hashtag:
29
+                link['class'] = ['badge', 'bg-info', 'text-decoration-none']
30
+            else:
31
+                link['class'] = ['link-info', 'text-decoration-none']
28
         e['description'] = str(soup)
32
         e['description'] = str(soup)
29
         images = []
33
         images = []
30
         videos =[]
34
         videos =[]

Loading…
取消
儲存