Last active
December 21, 2015 00:19
-
-
Save ruthienachmany/6219430 to your computer and use it in GitHub Desktop.
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
every 1.minute do | |
rake "import_tweets:tweets" | |
end |
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 'twitter' | |
require_relative '../../app/workers/tweet_scrape_worker' | |
namespace :import_tweets do | |
task :tweets => :environment do | |
Student.all.each do |student| | |
TweetScrapeWorker.perform_async(student.id) | |
sleep 1 | |
end | |
end | |
end |
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
class TweetScraper | |
attr_accessor :student | |
def initialize(student) | |
@student = student | |
end | |
def scrape_feed | |
Twitter.user_timeline(student.twitter_handle, options = {:count => 200}).each do |tweet| | |
if Tweet.where(:tweet_id => tweet.id).empty? | |
tweet_post = Tweet.new | |
tweet_post.student_id = student.id | |
tweet_post.tweet_id = tweet.id | |
tweet_post.tweet_content = tweet.text | |
tweet_post.tweet_published_at = tweet.created_at | |
tweet_post.profile_image_url = tweet.profile_image_url | |
tweet_post.save! | |
end | |
end | |
end | |
end | |
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
class TweetScrapeWorker | |
include Sidekiq::Worker | |
def perform(student_id) | |
student = Student.find(student_id) | |
TweetScraper.new(student).scrape_feed | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment