Browse Source

Highlight links to topic tag

master
The Dod 1 year ago
parent
commit
524ba6c550
1 changed files with 5 additions and 1 deletions
  1. 5
    1
      mymastotag.py

+ 5
- 1
mymastotag.py View File

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…
Cancel
Save