Skip to content

Instantly share code, notes, and snippets.

@tedkulp
Last active January 6, 2020 06:33
Show Gist options
  • Save tedkulp/4746870 to your computer and use it in GitHub Desktop.
Save tedkulp/4746870 to your computer and use it in GitHub Desktop.
Node.js server to turn twitter favorites into an RSS feed. Twitter api v1.1 is killing this, so I made my own and put it on heroku.
http = require 'http'
twitter = require 'ntwitter'
express = require 'express'
moment = require 'moment'
app = express()
client = new twitter
consumer_key: ''
consumer_secret: ''
access_token_key: ''
access_token_secret: ''
app.get '/favorites', (req, res) ->
client.get '/favorites/list.json',
include_entities: 1
count: 20
, (err, data) ->
output = """
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com" version="2.0" xmlns:georss="http://www.georss.org/georss">
<channel>
<title>Twitter / Favorites from tedkulp</title>
<link>http://twitter.com/tedkulp/favorites</link>
<atom:link type="application/rss+xml" href="http://api.twitter.com/1/favorites.rss?screen_name=tedkulp" rel="self"/>
<description>Twitter updates favorited by Ted Kulp / tedkulp.</description>
<language>en-us</language>
<ttl>40</ttl>
"""
data.forEach (tweet) ->
output += """
<item>
<title>#{tweet.text}</title>
<description>#{tweet.text}</description>
<pubDate>#{moment(tweet.created_at).utc().format('ddd, DD MMM YYYY HH:mm:ss ZZ')}</pubDate>
<guid>http://twitter.com/#{tweet.user.screen_name}/status/#{tweet.id_str}</guid>
<link>http://twitter.com/#{tweet.user.screen_name}/status/#{tweet.id_str}</link>
<author>#{tweet.user.screen_name}</author>
</item>
"""
output += """
</channel>
</rss>
"""
res.setHeader 'Content-Type', 'application/rss+xml; charset=utf-8'
res.send output
port = process.env.PORT || 4000
app.listen port
console.log "Started on port #{port}"
{
"name": "feedme",
"version": "0.0.1",
"author": "Ted Kulp <ted@tedkulp.com>",
"engines": {
"node": "0.8.x",
"npm": "1.1.x"
},
"dependencies": {
"coffee-script": "1.4.0",
"express": "3.x",
"moment": "1.x",
"ntwitter": "0.x"
}
}
web: coffee app.coffee
@julien51
Copy link

Pretty cool! Is there a way to generate the feed when there's a new tweet and "cache" the file so that it's much faster to load?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment