Batt

Friday, May 3, 2013

Basic Elements of Python Twitter

In this assignment, you will

●      access the twitter Application Programming Interface(API) using python.
●      estimate the public's perception (the sentiment) of a particular term or phrase.
●      analyze the relationship between location and mood based on a sample of twitter data.

 Twitter Application Programming Interface(API) using python

 https://dev.twitter.com/docs/api/1.1/post/statuses/filter

                 Both GET and POST requests are supported, but GET requests with too many parameters may cause the request to be rejected for excessive URL length. Use a POST request to avoid long URLs.

                The track, follow, and locations fields should be considered to be combined with an OR operator. track=foo&follow=1234 returns Tweets matching "foo" OR created by user 1234.

               The default access level allows up to 400 track keywords, 5,000 follow userids and 25 0.1-360 degree location boxes. If you need elevated access to the Streaming API,

Resource URL: 

https://stream.twitter.com/1.1/statuses/filter.json 

No filter parameters found. Expect at least one parameter: follow track locations 
*Note: At least one predicate parameter (follow, locations, or track) must be specified.

https://stream.twitter.com/1.1/statuses/filter.json?delimited=length&track=sri%20lanka

 2256
{"created_at":"Sat May 04 07:02:20 +0000 2013","id":330578119138369536,
"id_str":"330578119138369536",
"text":"Exciting travel deals from Cobone #cyprus #Sri Lanka

 2256
indicates how many bytes to read off of the stream to get the rest of the Tweet (including \r\n). The next length delimiter will occur exactly after 2256 bytes.

Location :

https://stream.twitter.com/1.1/statuses/filter.json?limited=103&track=sri%20lanka&locations=6.56,79.50,7,81

HTTP : POST/GET
http://www.w3schools.com/tags/ref_httpmethods.asp


Python Twitter Tutorial -01

{"created_at":"Sat May 04 04:22:57 +0000 2013",
 "id":330538011341234176,
 "id_str":"330538011341234176",
 "text":"RT @SincerlySweet_: \ud83d\udc4c\ud83d\ude0a \u201c@Urban_Supremacy: @SincerlySweet_ following back \ud83d\ude18\u201d",
 "source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e",
 "truncated":false,
 "in_reply_to_status_id":null,
 "in_reply_to_status_id_str":null,
 "in_reply_to_user_id":null,
 "in_reply_to_user_id_str":null,
 "in_reply_to_screen_name":null,
 "user":{"id":141814917,"id_str":"141814917","name":"Se\u00f1or Fresco  \ue420",
         "screen_name":"Urban_Supremacy",
         "location":"On the 8 lanes.",
         "url":"http:\/\/Duckingfope.tumblr.com",
         "description":"Young loving with Faith. | Running 400s with @est_ijump. \nIG: dorienj",
         "protected":false,
         "followers_count":1820,
         "friends_count":1496,
         "listed_count":8,
         "created_at":"Sun May 09 03:49:04 +0000 2010",
         "favourites_count":421,
         "utc_offset":-18000,
         "time_zone":"Quito",
         "geo_enabled":true,
         "verified":false,
         "statuses_count":66654,
         "lang":"en",
         "contributors_enabled":false,
         "is_translator":false,
         "profile_background_color":"000000",
         "profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/334327570\/ted-ginn-pictures__23_.jpg",
         "profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/334327570\/ted-ginn-pictures__23_.jpg",
         "profile_background_tile":true,
         "profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/3571540930\/797ea4e4b52b01458a028ef6923735c0_normal.jpeg",
         "profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/3571540930\/797ea4e4b52b01458a028ef6923735c0_normal.jpeg",
         "profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/141814917\/1354820570",
         "profile_link_color":"F50A0A",
         "profile_sidebar_border_color":"FF0000",
         "profile_sidebar_fill_color":"DDEEF6",
         "profile_text_color":"080808",
         "profile_use_background_image":true,
         "default_profile":false,
         "default_profile_image":false,
         "following":null,
         "follow_request_sent":null,
         "notifications":null},
 "geo":null,
 "coordinates":null,
 "place":null,
 "contributors":null,
 "retweeted_status":{"created_at":"Sat May 04 04:22:35 +0000 2013",
                     "id":330537916671602688,
                     "id_str":"330537916671602688",
                     "text":"\ud83d\udc4c\ud83d\ude0a \u201c@Urban_Supremacy: @SincerlySweet_ following back \ud83d\ude18\u201d",
                     "source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e",
                     "truncated":false,
                     "in_reply_to_status_id":330537559937658880,
                     "in_reply_to_status_id_str":"330537559937658880",
                     "in_reply_to_user_id":141814917,
                     "in_reply_to_user_id_str":"141814917",
                     "in_reply_to_screen_name":"Urban_Supremacy",
                     "user":{"id":172959417,"id_str":"172959417",
                             "name":"Sweeeeet",
                             "screen_name":
                             "SincerlySweet_",
                             "location":"Buffuckalo",
                             "url":null,
                             "description":"Listen ... Either you're gonna follow me or not *shrugs* IG - SincerlySweet_ \n#BelleAyisyen",
                             "protected":false,
                             "followers_count":998,
                             "friends_count":325,
                             "listed_count":42,
                             "created_at":"Sat Jul 31 01:52:25 +0000 2010",
                             "favourites_count":548,
                             "utc_offset":-18000,
                             "time_zone":"Quito",
                             "geo_enabled":false,
                             "verified":false,
                             "statuses_count":19819,
                             "lang":"en",
                             "contributors_enabled":false,
                             "is_translator":false,
                             "profile_background_color":"FCFCFC",
                             "profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/528460809\/stars.jpg",
                             "profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/528460809\/stars.jpg",
                             "profile_background_tile":true,
                             "profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/3542945847\/dc55c8819e6fdc0290188cca01a50392_normal.jpeg",
                             "profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/3542945847\/dc55c8819e6fdc0290188cca01a50392_normal.jpeg",
                             "profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/172959417\/1356018723",
                             "profile_link_color":"F75454",
                             "profile_sidebar_border_color":"292328",
                             "profile_sidebar_fill_color":"FFFFFF",
                             "profile_text_color":"E60000",
                             "profile_use_background_image":true,
                             "default_profile":false,
                             "default_profile_image":false,
                             "following":null,
                             "follow_request_sent":null,
                             "notifications":null},
                     "geo":null,
                     "coordinates":null,
                     "place":null,
                     "contributors":null,
                     "retweet_count":1,
                     "favorite_count":0,
                     "entities":{"hashtags":[],
                                 "symbols":[],
                                 "urls":[],
                                 "user_mentions":[{"screen_name":"Urban_Supremacy",
                                                   "name":"Se\u00f1or Fresco  \ue420",
                                                   "id":141814917,
                                                   "id_str":"141814917",
                                                   "indices":[4,20]},
                                                  {"screen_name":"SincerlySweet_",
                                                   "name":"Sweeeeet",
                                                   "id":172959417,
                                                   "id_str":"172959417",
                                                   "indices":[22,37]}]},
                     "favorited":false,
                     "retweeted":false,"lang":"de"},
 "retweet_count":0,
 "favorite_count":0,
 "entities":{"hashtags":[],
             "symbols":[],
             "urls":[],
             "user_mentions":[{"screen_name":"SincerlySweet_",
                               "name":"Sweeeeet",
                               "id":172959417,
                               "id_str":"172959417",
                               "indices":[3,18]},
                              {"screen_name":"Urban_Supremacy",
                               "name":"Se\u00f1or Fresco  \ue420",
                               "id":141814917,
                               "id_str":"141814917",
                               "indices":[24,40]},
                              {"screen_name":"SincerlySweet_",
                               "name":"Sweeeeet",
                               "id":172959417,
                               "id_str":"172959417",
                               "indices":[42,57]}]},
 "favorited":false,
 "retweeted":false,
 "filter_level":"low"}