Skip to content

Instantly share code, notes, and snippets.

@aytch
Created January 15, 2013 13:27
Show Gist options
  • Select an option

  • Save aytch/4538619 to your computer and use it in GitHub Desktop.

Select an option

Save aytch/4538619 to your computer and use it in GitHub Desktop.
Quick hack for grabbing Twitter status in Cinch
require 'Nokogiri'
require 'open-uri
# current regex string matches too much stuff. Trying https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+)$ instead
on :message, /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i do |m, message|
# on :message, /https?:\/\/(www.)?twitter.com(.+)\W/i do |m, message|
url = message.to_s
doc = Nokogiri::HTML(open(url))
user = doc.at_css("span.username.js-action-profile-name b").text
status = doc.xpath("//div[3]/div/div/div/div/p").text[/\S(.+)/]
message = "Twitter | @#{user}: #{status}"
m.reply message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment