Saturday 15 January 2011

ruby on rails - trying to save tweets into a model -


So I think I've got pieces for it but are unable to solve the puzzle.

So I have a user model that can follow a number of keywords (queries). The Association is like this:

User

  is_Im: Campaign # They can add and delete keywords in this Association: Alerts via: Campaigns  

Now what I would like to do, it detects ways that search through those User.campaigns, saves them in the alert, so in this way I can see which keywords related to the query (Campaign_ID Via).

What do I have here:

  keywords = current_user.campaigns.map (&: keywords) Current_user.twitter.search (keyword, result_type: 'recent'). Le (5) .collect do | Tweet | "# {Tweet.edit} # {tweet.}} ID"  

Now there is a problem in my code, which is an array of keywords, what i want to do it once Searching through the array.

Then I want to save it in the alert table. Where my columns are 'tweet_id' and 'owner_id' and 'campaign_id'.

Ideally I have a cron job that does every 15 minutes.

I have no clue where to begin with any thoughts?

If you are looking for all, then search for each individual keyword, something like this Should: Edit based on explanation from OP

  current_user.campaigns.each do | Campaign | Current_user.twitter.search (campaign.keyword, result_type: 'Recent'). Take (5). MAP | Tweet | "# {Tweet.edit} # {tweet .eur}." #new_alert = current_user.alerts.create (Campaign: Campaign ....) End End  

Note that there may be a way to be twitter. Search will return only 5 results, which will be unnecessary.

Note that I have your Map and. Have changed - they are mostly interchangeable, but meaningfully. I "recover some values" for me and. Map means "take some action on every value".

Does that help?


No comments:

Post a Comment