Created
May 30, 2017 20:35
-
-
Save weapp/03c1411bbff5bdc4a58b2be1bc740ffe to your computer and use it in GitHub Desktop.
dummy foxy example
This file contains 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
#!/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 |
This file contains 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
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