Skip to content

Instantly share code, notes, and snippets.

@notverypc
Created February 22, 2016 20:28
Show Gist options
  • Save notverypc/a69b2f66536c5a7a62d3 to your computer and use it in GitHub Desktop.
Save notverypc/a69b2f66536c5a7a62d3 to your computer and use it in GitHub Desktop.
FirstTrafficAlerts
#!/usr/bin/python
import feedparser
# Function to fetch the rss feed and return the parsed RSS
def parseRSS( rss_url ):
return feedparser.parse( rss_url )
# Function grabs the rss feed headlines (titles) and returns them as a list
def getHeadlines( rss_url ):
headlines = []
feed = parseRSS( rss_url )
for newsitem in feed['items']:
headlines.append(newsitem['title'])
headlines.append(newsitem['summary'])
return headlines
# A list to hold all headlines
allheadlines = []
# List of RSS feeds that we will fetch and combine
newsurls = {
'TravelNews': 'http://m.highways.gov.uk/datexphase2/dtxEventsApi.aspx?eventtype=1&src=a1|a14|m11|a505',
}
# Iterate over the feed urls
for key,url in newsurls.items():
# Call getHeadlines() and combine the returned headlines with allheadlines
allheadlines.extend( getHeadlines( url ) )
# Iterate over the allheadlines list and print each headline
for hl in allheadlines:
print(hl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment