Skip to content

Instantly share code, notes, and snippets.

@youpy
Last active December 16, 2015 14:49
Show Gist options
  • Save youpy/5451931 to your computer and use it in GitHub Desktop.
Save youpy/5451931 to your computer and use it in GitHub Desktop.
Notify new entry for Facebook's feed ticker
# require RubyCocoa
%w/ubygems grope pit terminal-notifier/.each {|g| require g }
def name(item)
elem = item.querySelector('.actorName') || item.querySelector('.passiveName')
elem.innerText.strip
end
def main
url = 'https://www.facebook.com/'
env = Grope::Env.new
env.load(url)
if env.document.title !~ /^Facebook/
config = Pit.get("facebook.com", :require => {
'username' => 'your username in facebook',
'password' => 'your password in facebook'
})
doc = env.document
doc.getElementById('email').value = config['username']
doc.getElementById('pass').value = config['password']
doc.getElementById('login_form').submit
env.wait(1)
end
last = nil
# to enable ticker
env.window.resizeTo(1280, 100);
loop do
env.load('https://www.facebook.com/')
js = env.eval('return Grope')
items = nil
env.wait_until(:timeout => 20) do
env.wait(3)
items = env.document.querySelectorAll('.fbFeedTickerStory').map {|item| item }
items.size > 0
end
items.reverse.each do |item|
timestamp = item.getAttribute('data-ticker-timestamp').to_i
if !last || last < timestamp
last = timestamp
TerminalNotifier.notify(
item.querySelector('.tickerFeedMessage').innerText.strip,
:title => name(item)
)
end
end
env.wait(3)
sleep 3
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment