Skip to content

Instantly share code, notes, and snippets.

@weapp
Created May 30, 2017 20:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weapp/03c1411bbff5bdc4a58b2be1bc740ffe to your computer and use it in GitHub Desktop.
Save weapp/03c1411bbff5bdc4a58b2be1bc740ffe to your computer and use it in GitHub Desktop.
dummy foxy example
#!/usr/bin/env ruby
%w(logger json ostruct bundler/setup).each(&method(:require))
Bundler.require(:default, ENV["APP_ENV"] || "development")
class TwClient < Foxy::Client
# def raw_with_cache(options, cacheopts)
# cache.html("cabify") do
# raw(options)
# end
# end
def timeline
eraw(path: "https://twitter.com/search?f=tweets&vertical=default&q=cabify")
.foxy
.css("#timeline li.js-stream-item .content")
end
def first_tweet
tweet = timeline.first
{
username: tweet.css("span.username").first.joinedtexts,
image: tweet.css("img.avatar").first.attr("src"),
text: tweet.css(".tweet-text").first.joinedtexts
}
end
def timeline_html
cache.html("timeline") { timeline.rebuild }
end
end
class App
class << self
def logger
@logger ||= Logger.new(STDOUT)
end
def debug(obj)
Pry::ColorPrinter.pp(obj) rescue p obj
obj
end
def run
loop do
tweet = client.first_tweet
if tweet != @last_tweet
debug tweet
puts
end
sleep(1)
@last_tweet = tweet
end
end
def client
@client ||= TwClient.new
end
def env
ENV["APP_ENV"] || "development"
end
end
end
App.run if __FILE__ == $PROGRAM_NAME
source "https://rubygems.org"
gem "foxy"
group :development, :test do
gem "pry"
gem "pry-byebug"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment