-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfweets.rb
57 lines (48 loc) · 1.42 KB
/
fweets.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'sinatra/base'
require 'twitter'
require 'rss'
class Fweets < Sinatra::Base
def to_rss(tweets, user, title, link)
content_type "application/rss+xml; charset=utf-8"
rss = RSS::Maker.make("2.0") do |maker|
maker.channel.author = user
maker.channel.updated = Time.now.to_s
maker.channel.title = title
maker.channel.description = title
maker.channel.link = link
tweets.each do |tweet|
maker.items.new_item do |item|
item.link = "http://twitter.com/#{tweet.from_user}/status/#{tweet.id}"
text = "#{tweet.from_user}: #{tweet.full_text}"
item.title = text
item.description = text
item.updated = tweet.created_at
item.guid.content = tweet.id.to_s
item.author = tweet.from_user
end
end
end
rss.to_s
end
get '/tweets/:user' do
user = params[:user]
to_rss(Twitter.user_timeline(user),
user,
"@#{user} tweets",
"http://twitter.com/#{user}")
end
get '/favs/:user' do
user = params[:user]
to_rss(Twitter.favorites(user),
user,
"@#{user} favorites",
"http://twitter.com/#{user}/favorites")
end
get '/hashtag/:hashtag' do
hashtag = params[:hashtag]
to_rss(Twitter.search("##{hashtag} -rt").results,
hashtag,
"##{hashtag} search",
"https://twitter.com/search?q=%#{hashtag}")
end
end