Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created March 25, 2014 14:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save emad-elsaid/9763040 to your computer and use it in GitHub Desktop.
Save emad-elsaid/9763040 to your computer and use it in GitHub Desktop.
Get your twitter Now playing stream
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
# Idea of : Thibault (@EyeWriteCode)
require 'Twitter' #gem install twitter
begin
# Create a read application from :
# https://apps.twitter.com
# authenticate it for your account
# fill in the following
config = {
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
}
sClient = Twitter::Streaming::Client.new(config)
rClient = Twitter::REST::Client.new(config)
following = rClient.friend_ids.to_a
topics = ['#NP', '#NW', '#nowplaying', '#now_playing']
sClient.filter(track: topics.join(',')) do |tweet|
if tweet.is_a?(Twitter::Tweet)
text = tweet.text
.gsub(/[#@]\S+/,'')
.gsub(/\n+/,' ')
.gsub(/\s{2,}/,'')
.strip
user = tweet.user
puts "#{user.screen_name} : #{text}" if following.include? user.id
end
end
rescue
puts 'error occurred, waiting for 5 seconds'
sleep 5
retry
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment