Created
January 27, 2009 21:23
-
-
Save papajuans/53557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import simplejson | |
import urllib | |
import PyRSS2Gen | |
hn_url = "http://news.ycombinator.com/" | |
#Run the YQL and get the JSON back | |
yql_url = "http://query.yahooapis.com/v1/public/yql?q=%20select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fnews.ycombinator.com%2Fnewest%22%20and%20xpath%3D'%2F%2Ftd%5B%40class%3D%22title%22%5D%2Fa'&format=json&callback=" | |
yql_results = urllib.urlopen(yql_url) #The query will return JSON | |
yql_json = simplejson.load(yql_results) | |
results = yql_json['query']['results']['a'] | |
#Construct the RSS | |
rss = PyRSS2Gen.RSS2(title = "news.ycom Newest posts",link = "http://news.ycombinator.com/newest",description = "RSS feed of all the newest posts.") | |
for item in results: | |
if item['href'].count("http://") <= 0: | |
item['href'] = hn_url + item['href'] | |
rss.items.append(PyRSS2Gen.RSSItem(title=item['content'],link=item['href'],guid=item['href'])) | |
#Save the file | |
rss.write_xml(open("news.xml", "w")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment