Published: Tue 03 April 2018
Python RSS Tutorials
I recently wrote a small a python script to parse blog feeds and then
tweet them out via Twitter. It randomly takes the first 5 RSS entries of
a feed and them tweets one out. You'll need to get an
key <https://developer.twitter.com/>__ from Twitter and the
credentials, but it's a neat way to keep your readers updated of the
various feeds you read or write. Just replace the
'XXXXXXXXXXXXXXXXXXXXXX' with the various keys you get from Twitter.
from twython import Twython , TwythonError
CONSUMER_KEY = 'XXXXXXXXXXXXXXXXXXXXXX'
CONSUMER_SECRET = 'XXXXXXXXXXXXXXXXXXXXXX'
ACCESS_KEY = 'XXXXXXXXXXXXXXXXXXXXXX'
ACCESS_SECRET = 'XXXXXXXXXXXXXXXXXXXXXX'
num = random . randint ( 0 , 5 )
d = feedparser . parse ( 'http://www.neuralmarkettrends.com/feed' )
api = Twython ( CONSUMER_KEY , CONSUMER_SECRET , ACCESS_KEY , ACCESS_SECRET )
status_text = 'Fresh: ' + d [ 'entries' ][ num ][ 'title' ] + ' link: ' + d [ 'entries' ][ num ][ 'link' ] + ' #NMT'
api . update_status ( status = status_text )
except TwythonError as e :
print ( e )
Proudly powered by
Pelican, which takes great advantage of Python.
The theme is by
Smashing Magazine, thanks!