added direct link feature

This commit is contained in:
Navan Chauhan 2020-11-10 20:19:02 +05:30
parent a45c659334
commit 8b1864af54
1 changed files with 17 additions and 0 deletions

17
main.py
View File

@ -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")