Created
January 6, 2016 22:24
-
-
Save jpo/09370eefc7f0189de5d5 to your computer and use it in GitHub Desktop.
Twitter Scraping Job for Dashing
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
require 'nokogiri' | |
require 'open-uri' | |
# Retrieves publicly available tweets for a twitter account. | |
# This job is intended to be used with the comments widget. | |
# Config | |
# ------ | |
twitter_username = ENV['TWITTER_USERNAME'] || '[TWITTER USERNAME]' # Do not include the @ symbol | |
twitter_avatar = '[TWITTER AVATAR URL]' # e.g. https://pbs.twimg.com/profile_images/... | |
SCHEDULER.every '5m', :first_in => 0 do |job| | |
html = Nokogiri::HTML(open("https://twitter.com/#{twitter_username}")) | |
tweets = html.css('.tweet-text').map do |tweet| | |
{ name: "@#{twitter_username}", body: tweet.text, avatar: twitter_avatar } | |
end | |
send_event 'tweets', comments: tweets | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment