Created
January 15, 2013 13:27
-
-
Save aytch/4538619 to your computer and use it in GitHub Desktop.
Quick hack for grabbing Twitter status in Cinch
This file contains hidden or 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 | |
| # 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