Skip to content

Instantly share code, notes, and snippets.

@jpo
Created January 6, 2016 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpo/09370eefc7f0189de5d5 to your computer and use it in GitHub Desktop.
Save jpo/09370eefc7f0189de5d5 to your computer and use it in GitHub Desktop.
Twitter Scraping Job for Dashing
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