Created
March 25, 2014 14:31
-
-
Save emad-elsaid/9763040 to your computer and use it in GitHub Desktop.
Get your twitter Now playing stream
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
#!/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