Skip to content

Instantly share code, notes, and snippets.

@antillas21
Created July 4, 2012 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antillas21/3048337 to your computer and use it in GitHub Desktop.
Save antillas21/3048337 to your computer and use it in GitHub Desktop.
Tweet capturado con TweetStream

##Flujo

  • Abrir un cliente al Streaming API de twitter via la gema TweetStream
  • Este cliente debe estar siempre funcionando y proveer un comportamiento cuando haya necesidad de reconnectarse (por problemas en twitter y diversos) y en caso de error (por las mismas causas) # Leer documentacion de la gema
  • El cliente debe enviar todos los tweets capturados en base a un query='on @dimensions, @dimensions' a un Array o a un queue.
  • A través de un background_job, procesar el queue, leyendo de cada tweet capturado, el atributo :expanded_url (provisionando que puede ser nulo o empty)
  • El background_job debe hacer una búsqueda en los feed_entries con ese valor capturado. Si encuentra un match, entonces += 1 a su tweet_count.
#<Twitter::Status:0x00000101127cd8
@attrs=
{:entities=>
{:user_mentions=>
[{:indices=>[31, 42],
:id_str=>"248742679",
:name=>"Dimensions",
:screen_name=>"dimensions",
:id=>248742679}],
:urls=>
[{:indices=>[43, 63],
:url=>"http://t.co/I2ndodld",
:expanded_url=>
"http://slog.thestranger.com/slog/archives/2012/07/03/why-are-american-kids-so-spoiled",
:display_url=>"slog.thestranger.com/slog/archives/…"}],
:hashtags=>[]},
:coordinates=>nil,
:geo=>nil,
:text=>"Interesting article I found on @dimensions http://t.co/I2ndodld",
:place=>nil,
:created_at=>"Wed Jul 04 16:54:50 +0000 2012",
:possibly_sensitive_editable=>true,
:retweet_count=>0,
:in_reply_to_user_id=>nil,
:retweeted=>false,
:possibly_sensitive=>false,
:in_reply_to_status_id=>nil,
:source=>
"<a href=\"http://twitter.com/tweetbutton\" rel=\"nofollow\">Tweet Button</a>",
:in_reply_to_status_id_str=>nil,
:truncated=>false,
:id_str=>"220561316258131969",
:in_reply_to_user_id_str=>nil,
:favorited=>false,
:user=>
{:default_profile_image=>false,
:lang=>"es",
:time_zone=>"Pacific Time (US & Canada)",
:profile_background_color=>"131516",
:followers_count=>156,
:profile_image_url=>
"http://a0.twimg.com/profile_images/1197477861/me3a_normal.jpg",
:verified=>false,
:profile_background_tile=>true,
:favourites_count=>17,
:created_at=>"Fri Mar 12 20:27:42 +0000 2010",
:friends_count=>350,
:contributors_enabled=>false,
:geo_enabled=>true,
:profile_sidebar_fill_color=>"efefef",
:url=>"http://antillas.tumblr.com",
:follow_request_sent=>nil,
:following=>nil,
:profile_background_image_url_https=>
"https://si0.twimg.com/images/themes/theme14/bg.gif",
:description=>
"Readings, ramblings and musings of an aspiring human being",
:profile_sidebar_border_color=>"eeeeee",
:show_all_inline_media=>false,
:listed_count=>5,
:notifications=>nil,
:location=>"Mexicali, Mexico",
:statuses_count=>1420,
:profile_use_background_image=>true,
:id_str=>"122466898",
:default_profile=>false,
:profile_text_color=>"333333",
:protected=>false,
:is_translator=>false,
:profile_background_image_url=>
"http://a0.twimg.com/images/themes/theme14/bg.gif",
:profile_image_url_https=>
"https://si0.twimg.com/profile_images/1197477861/me3a_normal.jpg",
:screen_name=>"antillas21",
:name=>"Antonio Antillon",
:profile_link_color=>"009999",
:id=>122466898,
:utc_offset=>-28800},
:id=>220561316258131969,
:contributors=>nil,
:in_reply_to_screen_name=>nil}>
# tweet representa el tweet capturado.
# si hacemos un pp tweet.attrs[:entities]
{:user_mentions=>
[{:indices=>[31, 42],
:id_str=>"248742679",
:name=>"Dimensions",
:screen_name=>"dimensions",
:id=>248742679}],
:urls=>
[{:indices=>[43, 63],
:url=>"http://t.co/I2ndodld",
:expanded_url=>
"http://slog.thestranger.com/slog/archives/2012/07/03/why-are-american-kids-so-spoiled",
:display_url=>"slog.thestranger.com/slog/archives/…"}],
:hashtags=>[]}
# notamos como :urls es un array, y que en este caso, solo contiene el url de destino de la noticia
# http://slog.thestranger.com/slog/archives/2012/07/03/why-are-american-kids-so-spoiled
# entonces abramos el primer elemento de ese array
# pp tweet.attrs[:entities][:urls][0]
{:indices=>[43, 63],
:url=>"http://t.co/I2ndodld",
:expanded_url=>
"http://slog.thestranger.com/slog/archives/2012/07/03/why-are-american-kids-so-spoiled",
:display_url=>"slog.thestranger.com/slog/archives/…"}
# lo que necesito es capturar el valor de :expanded_url
@feed_entry_url = tweet.attrs[:entities][:urls][0][:expanded_url]
# => "http://slog.thestranger.com/slog/archives/2012/07/03/why-are-american-kids-so-spoiled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment