From 8b1864af54f874f22da69a48dbb8c54aa816a4ac Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 10 Nov 2020 20:19:02 +0530 Subject: [PATCH] added direct link feature --- main.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.py b/main.py index 9d2828d..7c79f9f 100644 --- a/main.py +++ b/main.py @@ -45,6 +45,7 @@ def GetPosts(feed): ToIgnore = [] ReadSummary = True URL = None + ShowLink = False ToRead = 5 try: URL = feeds[feed]["URL"] @@ -63,6 +64,10 @@ def GetPosts(feed): ToRead = eval(feeds[feed]["ToRead"]) except: None + try: + ShowLink = eval(feeds[feed]["LINK"]) + except KeyError: + None rss = feedparser.parse(URL) maximum = len(rss.entries) @@ -74,6 +79,7 @@ def GetPosts(feed): posts = [] summaries = [] + links = [] added = 0 while count != maximum and added != ToRead: Skip = False @@ -88,6 +94,8 @@ def GetPosts(feed): posts.append(Title) if ReadSummary: summaries.append(Summary) + if ShowLink: + links.append(rss.entries[count].link) count += 1 for idx in range(len(posts)): @@ -98,9 +106,14 @@ def GetPosts(feed): Posts[idx]["post"]["summary"] = summaries[idx].encode('utf-8') else: Posts[idx]["summary"] = None + if ShowLink: + Posts[idx]["post"]["link"] = links[idx].encode('utf-8') + else: + Posts[idx]["post"]["link"] = None Posts["NoOfPosts"] = len(posts) Posts["Summary"] = ReadSummary + Posts["ShowLink"] = ShowLink return Posts @@ -121,6 +134,10 @@ if markdown: if posts[feed]["Summary"]: mdfile.write(" - ") mdfile.write(posts[feed][idx]["post"]["summary"].decode('utf-8')) + if posts[feed]["ShowLink"]: + mdfile.write(" - [link](%s)"%posts[feed][idx]["post"]["link"].decode('utf-8')) + mdfile.write("\n\n") + elif posts[feed]["Summary"]: mdfile.write("\n\n") else: mdfile.write("\n")