Created
October 25, 2009 22:47
-
-
Save uhhuhyeah/218297 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
class Twitter < YqlTable | |
def grab | |
category = Category.find_by_name("Tweets") | |
terms = ["ucsd", "ucla", "csupomona"] # TODO Needs to pull from colleges | |
result_set = self.query(terms).run | |
raise result_set.inspect unless result_set["query"] && result_set["query"]["results"] | |
default_user = User.find_by_login("twitter") || User.first | |
result_set["query"]["results"]["entry"].each do |result| | |
author = User.find_by_twitter_name(result["author"]["uri"].split('/').last) || default_user | |
post = category.posts.create!(:title => result["title"], :raw_post => result["content"]["content"], :service_id => result["id"], :user => author, :published_as => 'live') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment