Class: Tweetlr
Constant Summary collapse
- VERSION =
'0.1.17'
- API_ENDPOINT_TWITTER =
'http://search.twitter.com/search.json'
- API_ENDPOINT_TUMBLR =
'http://www.tumblr.com'
- TWITTER_RESULTS_PER_PAGE =
100
- TWITTER_RESULTS_TYPE =
'recent'
- UPDATE_PERIOD =
10 minutes
600
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Tweetlr
constructor
A new instance of Tweetlr.
Methods included from LogAware
Constructor Details
#initialize(args) ⇒ Tweetlr
Returns a new instance of Tweetlr.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tweetlr.rb', line 25 def initialize(args) log = Logger.new(STDOUT) if (Logger::DEBUG..Logger::UNKNOWN).to_a.index(args[:loglevel]) log.level = args[:loglevel] else log.level = Logger::INFO end log.debug "log level set to #{log.level}" LogAware.log=log @email = args[:tumblr_email] @password = args[:tumblr_password] @cookie = args[:cookie] @api_endpoint_twitter = args[:api_endpoint_twitter] || API_ENDPOINT_TWITTER @api_endpoint_tumblr = args[:api_endpoint_tumblr] || API_ENDPOINT_TUMBLR @whitelist = args[:whitelist] @shouts = args[:shouts] @update_period = args[:update_period] || UPDATE_PERIOD @whitelist.each {|entry| entry.downcase!} if @whitelist log.info "Tweetlr #{Tweetlr::VERSION} initialized. Ready to roll." end |
Class Method Details
.crawl(config) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tweetlr.rb', line 47 def self.crawl(config) log.debug "#{self}.crawl() using config: #{config.inspect}" twitter_config = { :since_id => config[:since_id] || config[:start_at_tweet_id], :search_term => config[:terms] || config[:search_term] , :results_per_page => config[:results_per_page] || TWITTER_RESULTS_PER_PAGE, :result_type => config[:result_type] || TWITTER_RESULTS_TYPE, :api_endpoint_twitter => config[:api_endpoint_twitter] || API_ENDPOINT_TWITTER } tumblr_config = { :tumblr_oauth_access_token_key => config[:tumblr_oauth_access_token_key], :tumblr_oauth_access_token_secret => config[:tumblr_oauth_access_token_secret], :tumblr_oauth_api_key => config[:tumblr_oauth_api_key], :tumblr_oauth_api_secret => config[:tumblr_oauth_api_secret], :tumblr_blog_hostname => config[:tumblr_blog_hostname] || config[:group] } twitter_config[:search_term] = URI::escape(twitter_config[:search_term]) if twitter_config[:search_term] log.info "starting tweetlr crawl..." response = {} response = Processors::Twitter::lazy_search(twitter_config) if response tweets = response['results'] if tweets tweets.each do |tweet| tumblr_post = Combinators::TwitterTumblr::generate_photo_post_from_tweet(tweet, {:whitelist => config[:whitelist], :embedly_key => config[:embedly_key], :group => config[:group]}) if tumblr_post.nil? || tumblr_post[:source].nil? log.warn "could not get image source: tweet: #{tweet} --- tumblr post: #{tumblr_post.inspect}" else log.debug "tumblr post: #{tumblr_post}" res = Processors::Tumblr.post tumblr_post.merge(tumblr_config) log.warn "tumblr response: #{res.header} #{res.body}" unless res.code == "201" end end # store the highest tweet id config[:since_id] = response['max_id'] end else log.error "twitter search returned no response. hail the failwhale!" end log.info "finished tweetlr crawl." return config end |