Skip to content

Commit

Permalink
Create headline fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
sreerajmp authored Dec 29, 2018
1 parent 84a5691 commit 5e65d9a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions headline fetcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import feedparser
d = feedparser.parse('https://www.hindustantimes.com/rss/topnews/rssfeed.xml')#paste the link of web rss here to fetch the feed from site.
print (d.feed.title)
#FUNCTION TO GET HEADLINES FROM SITE AND STORE IT TO LIST BY ITERATINTING THROUGH FEED
def getHeadlines( d ):
headlines = []
for newsitem in d['items']:
headlines.append(newsitem['title'])
return headlines
#PRINTING THE FEED TO TERMINAL WITH ENUMERATION TO EACH LINE
for count,hl in enumerate(getHeadlines(d),start=1):
print(count,hl)
#WRITING THE FEED TO A CSV FILE WITH ENUMERATION TO EACH FEED
with open("myfile.csv","w") as f:
for count,hl in enumerate(getHeadlines(d),start=1):
f.writelines('%d.'%count)
f.writelines(hl+'\n')

0 comments on commit 5e65d9a

Please sign in to comment.