Skip to content

Instantly share code, notes, and snippets.

@asaini
Created September 21, 2013 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaini/6651785 to your computer and use it in GitHub Desktop.
Save asaini/6651785 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": "twitter"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "<h1>Twitter Sentiment Analysis</h1>"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "<img src=\"https://blog.twitter.com/sites/all/themes/gazebo/img/twitter-bird-white-on-blue.png\"></img>"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Over the past few years <a href=\"https://twitter.com/\">Twitter</a> has grown to become a social platform for people to express their opinions. This presents us with an opportunity to use these opinions to gauge sentiment about a topic expressed by a large population. \n \nGive more background .... "
},
{
"cell_type": "markdown",
"metadata": {},
"source": "<strong>Pre-Requisites</strong>"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "This exercise requires the <a href=\"https://pypi.python.org/pypi/oauth2\">OAuth2</a> module. It can be easily installed using the <a href=\"https://pypi.python.org/pypi/pip\">pip</a> or <b>easy_install</b> \n\n $ pip install oauth2\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "<h2>Twitter API</h2>"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "In this exercise we will be using Twitter's <a href=\"https://dev.twitter.com/docs/api/1.1/get/search/tweets\">Search API</a>. This allows us to make requests from our program to Twitter, which return tweets about a particular topic. For example, I can ask for tweets about <a href=\"https://twitter.com/search?q=nyc&src=typd\">NYC</a>, or <a href=\"https://twitter.com/search?q=harlem&src=typd\">Harlem</a> etc. and the API will return tweets just like it does on the search webpage. \n \nTo be able to use the Search API, we need to register as Developer at https://dev.twitter.com/. Your existing twitter account credentials can be used to register as a developer. Once registered, you will be taken to the Twitter Developer's Page. Click on your profile on the upper right hand side of the page, and go to <b>My Applications</b>. \nAt the Applications page, click on the <b>Create a new application</b> button. Choose a Name for your application, write a short description of your choice and since we do not have a website for our application, put http://www.google.com to serve as a placeholder, Agree to Twitter's Terms and Conditions and hit the Create Application button. \n\nGo back to the <b>My Applications</b> page and you will see your application listed there. Click on your application link and you will be taken to Application's page. This page contains important details about your application. Out of the things listed on the page, the following are of interest to us: \n\n1. Consumer Key\n2. Consumer Secret\n3. Access Token\n4. Access Token Secret\n\nLet's get down to writing our program now..."
},
{
"cell_type": "markdown",
"metadata": {},
"source": "<h3>Getting your hands dirty</h3>"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Using your favorite text editor, create a Python script called <em>search.py</em> and paste the following piece of code."
},
{
"cell_type": "code",
"collapsed": false,
"input": "import oauth2 as oauth\nimport urllib2 as urllib\nimport json\n\naccess_token_key = \"xxxxxxxxxxxxxxxxxxxxxxxxx\"\naccess_token_secret = \"xxxxxxxxxxxxxxxxxxxxxxxxx\"\n\nconsumer_key = \"xxxxxxxxxxxxxxxxxxxxxxxxx\"\nconsumer_secret = \"xxxxxxxxxxxxxxxxxxxxxxxxx\"\n\n_debug = 0\n\noauth_token = oauth.Token(key=access_token_key, secret=access_token_secret)\noauth_consumer = oauth.Consumer(key=consumer_key, secret=consumer_secret)\n\nsignature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1()\n\nhttp_method = \"GET\"\n\n\nhttp_handler = urllib.HTTPHandler(debuglevel=_debug)\nhttps_handler = urllib.HTTPSHandler(debuglevel=_debug)\n\n'''\nConstruct, sign, and open a twitter request\nusing the hard-coded credentials above.\n'''\ndef twitterreq(url, method, parameters):\n req = oauth.Request.from_consumer_and_token(oauth_consumer,\n token=oauth_token,\n http_method=http_method,\n http_url=url, \n parameters=parameters)\n\n req.sign_request(signature_method_hmac_sha1, oauth_consumer, oauth_token)\n\n headers = req.to_header()\n\n if http_method == \"POST\":\n encoded_post_data = req.to_postdata()\n else:\n encoded_post_data = None\n url = req.to_url()\n\n opener = urllib.OpenerDirector()\n opener.add_handler(http_handler)\n opener.add_handler(https_handler)\n\n response = opener.open(url, encoded_post_data)\n\n return response",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": "The above code helps us to establish a connection with Twitter and confirm our identity. If you don't understand what is going in the few lines of code above don't worry. \n\nPopulate the <code>access_token_key</code>, <code>access_token_secret</code>, <code>consumer_key</code> and <code>consumer_secret</code> variables with the values obtained from your Application's Page, as described in the previous page. These values help Twitter know your identity and authenticate you using the <a href=\"http://en.wikipedia.org/wiki/OAuth\">OAuth</a> authorization standard. Again, don't worry too much if you don't understand the details here, the following section is what is of interest to us :) "
},
{
"cell_type": "markdown",
"metadata": {},
"source": "From Twitter's <a href=\"https://dev.twitter.com/docs/api/1.1/get/search/tweets\">Search API Documentation</a>, we see that we need to query their <b>Resource URL</b> with the additional parameters as listed on the page \n\nResource URL :\nhttps://api.twitter.com/1.1/search/tweets.json"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Create a function called <em>fetchsamples</em>, which takes as it's argument a variable called <em>parameters</em>. This <em>parameters</em> variable contains specific information about... \n \n1. The query on which we want to perform our search, eg, NYC, Harlem, \n2. What should be the language of the tweets returned, etc.\n \nThese parameters get appended to the Resource URL, eg. https://api.twitter.com/1.1/search/tweets.json?q=harlem&lang=en"
},
{
"cell_type": "code",
"collapsed": false,
"input": "def fetchsamples(parameters):\n url = \"https://api.twitter.com/1.1/search/tweets.json\"\n\n response = twitterreq(url, \"GET\", parameters)\n return response",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Let us see what our code can do, until now ... \n \nOpen a Python Shell in the same directory which contains the <em>search.py</em> program you wrote, \n\n $ python"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Let us <b>import</b> our code in the <em>search.py</em> module into our python shell"
},
{
"cell_type": "code",
"collapsed": false,
"input": "import search",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Let us check if it contains the function <code>fetchsamples</code>"
},
{
"cell_type": "code",
"collapsed": false,
"input": "fetchsamples",
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": "<function __main__.fetchsamples>"
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Okay, so that confirms that our <em>fetchsamples</em> method indeed got imported. Let us construct some parameters to pass on to this function. <em>parameters</em> should be a Python <a href=\"http://docs.python.org/2/tutorial/datastructures.html#dictionaries\">Dictionary</a>"
},
{
"cell_type": "code",
"collapsed": false,
"input": "parameters = {\n 'q' : 'nyc',\n 'lang': 'en',\n 'count': 10,\n }",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Okay, so we're ready to call our function <em>fetchsamples</em>"
},
{
"cell_type": "code",
"collapsed": false,
"input": "samples = fetchsamples(parameters)",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 20
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Let us explore what is inside <em>samples</em>"
},
{
"cell_type": "code",
"collapsed": false,
"input": "samples",
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 21,
"text": "<addinfourl at 69735776 whose fp = <socket._fileobject object at 0x4150e50>>"
}
],
"prompt_number": 21
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Hmm, that looks like some kind of Python Object.(Everything in Python is an Object!). Let us try to find out what kind of methods it supports, using Python's <a href=\"http://docs.python.org/2/library/functions.html#dir\">dir()</a> function. <b>dir()</b> will tell us what kind of methods we can call on samples."
},
{
"cell_type": "code",
"collapsed": false,
"input": "dir(samples)",
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": "['__doc__',\n '__init__',\n '__iter__',\n '__module__',\n '__repr__',\n 'close',\n 'code',\n 'fileno',\n 'fp',\n 'getcode',\n 'geturl',\n 'headers',\n 'info',\n 'msg',\n 'next',\n 'read',\n 'readline',\n 'readlines',\n 'url']"
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Okay, so the <em>samples</em> object has a <b>read()</b> method. Perhaps, that will allow us to read the response that Twitter sent for the query we made. Let us call the read() method on the <em>samples</em> object and assign it to the variable <b>text</b>. We had previously used the <b>read()</b> method in our <b>Reading and Writing to Files</b> tutorial as well. "
},
{
"cell_type": "code",
"collapsed": false,
"input": "text = samples.read()",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 22
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Ok, let us look what the text variable contains... \n<b>Note</b> : The contents of <em>text</em> will be different than what is show below since they will fetch you tweets from a different date/time."
},
{
"cell_type": "code",
"collapsed": false,
"input": "text",
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 23,
"text": "'{\"statuses\":[{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:17 +0000 2013\",\"id\":381445787013906432,\"id_str\":\"381445787013906432\",\"text\":\"RT @HeffronDrive: \\\\\"This is my view of NYC\\\\\"\\\\n:)\\\\n#NYC\\\\n#wwDoP http:\\\\/\\\\/t.co\\\\/ZHJhzjG4Tm\",\"source\":\"\\\\u003ca href=\\\\\"https:\\\\/\\\\/mobile.twitter.com\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eMobile Web (M2)\\\\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\":1471657284,\"id_str\":\"1471657284\",\"name\":\"Klaudia Henderson\",\"screen_name\":\"KlaudiaRusher\",\"location\":\"Poland\",\"description\":\"I\\'m 15.I LOVE GOD. I\\'m Polish Rusher. I love Logan. I like Heffron Drive, Victoria Justice, Max Schneider, Demi Lovato, Ariana Grande. I like volleyball.\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":119,\"friends_count\":220,\"listed_count\":0,\"created_at\":\"Fri May 31 08:43:48 +0000 2013\",\"favourites_count\":249,\"utc_offset\":10800,\"time_zone\":\"Athens\",\"geo_enabled\":false,\"verified\":false,\"statuses_count\":519,\"lang\":\"pl\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"0099B9\",\"profile_background_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_background_images\\\\/378800000007487043\\\\/4946bcfd1472c808559e0ae4d61d3ab8.jpeg\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_background_images\\\\/378800000007487043\\\\/4946bcfd1472c808559e0ae4d61d3ab8.jpeg\",\"profile_background_tile\":true,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/378800000313539558\\\\/6af56672153afd8c7574e565f9f0dbf7_normal.png\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/378800000313539558\\\\/6af56672153afd8c7574e565f9f0dbf7_normal.png\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/1471657284\\\\/1376756246\",\"profile_link_color\":\"0099B9\",\"profile_sidebar_border_color\":\"000000\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweeted_status\":{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:09:01 +0000 2013\",\"id\":381434900991447040,\"id_str\":\"381434900991447040\",\"text\":\"\\\\\"This is my view of NYC\\\\\"\\\\n:)\\\\n#NYC\\\\n#wwDoP http:\\\\/\\\\/t.co\\\\/ZHJhzjG4Tm\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/instagram.com\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eInstagram\\\\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\":29898542,\"id_str\":\"29898542\",\"name\":\"Kendall Schmidt\",\"screen_name\":\"HeffronDrive\",\"location\":\"\",\"description\":\"Enjoy Heffron Drive \\\\nThis is The Official Kendall Schmidt Twitter. I\\'m in the band @BigTimeRush \\\\nInfo:\\\\nhttp:\\\\/\\\\/t.co\\\\/R0zwSimvtO\\\\nhttp:\\\\/\\\\/t.co\\\\/a7HSHZoMUd\",\"url\":null,\"entities\":{\"description\":{\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/R0zwSimvtO\",\"expanded_url\":\"http:\\\\/\\\\/Www.Bigtimetour.com\\\\/events\",\"display_url\":\"Bigtimetour.com\\\\/events\",\"indices\":[103,125]},{\"url\":\"http:\\\\/\\\\/t.co\\\\/a7HSHZoMUd\",\"expanded_url\":\"http:\\\\/\\\\/smarturl.it\\\\/24seven\",\"display_url\":\"smarturl.it\\\\/24seven\",\"indices\":[126,148]}]}},\"protected\":false,\"followers_count\":1865569,\"friends_count\":615,\"listed_count\":8146,\"created_at\":\"Thu Apr 09 02:35:33 +0000 2009\",\"favourites_count\":9,\"utc_offset\":-25200,\"time_zone\":\"Pacific Time (US & Canada)\",\"geo_enabled\":false,\"verified\":true,\"statuses_count\":5586,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"000000\",\"profile_background_image_url\":\"http:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme14\\\\/bg.gif\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme14\\\\/bg.gif\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/378800000231515114\\\\/1b75355717f7cfdbfb9999eceb365e79_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/378800000231515114\\\\/1b75355717f7cfdbfb9999eceb365e79_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/29898542\\\\/1375465120\",\"profile_link_color\":\"FF0000\",\"profile_sidebar_border_color\":\"FFFFFF\",\"profile_sidebar_fill_color\":\"000000\",\"profile_text_color\":\"ABB9BF\",\"profile_use_background_image\":false,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":981,\"favorite_count\":906,\"entities\":{\"hashtags\":[{\"text\":\"NYC\",\"indices\":[28,32]},{\"text\":\"wwDoP\",\"indices\":[33,39]}],\"symbols\":[],\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/ZHJhzjG4Tm\",\"expanded_url\":\"http:\\\\/\\\\/instagram.com\\\\/p\\\\/eht-kHGCD3\\\\/\",\"display_url\":\"instagram.com\\\\/p\\\\/eht-kHGCD3\\\\/\",\"indices\":[40,62]}],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},\"retweet_count\":981,\"favorite_count\":0,\"entities\":{\"hashtags\":[{\"text\":\"NYC\",\"indices\":[46,50]},{\"text\":\"wwDoP\",\"indices\":[51,57]}],\"symbols\":[],\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/ZHJhzjG4Tm\",\"expanded_url\":\"http:\\\\/\\\\/instagram.com\\\\/p\\\\/eht-kHGCD3\\\\/\",\"display_url\":\"instagram.com\\\\/p\\\\/eht-kHGCD3\\\\/\",\"indices\":[58,80]}],\"user_mentions\":[{\"screen_name\":\"HeffronDrive\",\"name\":\"Kendall Schmidt\",\"id\":29898542,\"id_str\":\"29898542\",\"indices\":[3,16]}]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:16 +0000 2013\",\"id\":381445784216285185,\"id_str\":\"381445784216285185\",\"text\":\"Scheduled an open house for Atelier Sales Office - 212-563-6635 http:\\\\/\\\\/t.co\\\\/pQLtZO0VJd\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/www.streeteasy.com\\\\/\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eStreetEasy\\\\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\":190407775,\"id_str\":\"190407775\",\"name\":\"Atelier Condos Sales\",\"screen_name\":\"Ateliercondos\",\"location\":\"New York City\",\"description\":\"Atelier Condo sales and rentals. Call us at 212-563-6635. We offer luxury furnished units for a 3 month min.\",\"url\":\"http:\\\\/\\\\/t.co\\\\/PCxxSxhwRC\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/PCxxSxhwRC\",\"expanded_url\":\"http:\\\\/\\\\/www.youtube.com\\\\/watch?v=bfSKvULE5l4\",\"display_url\":\"youtube.com\\\\/watch?v=bfSKvU\\\\u2026\",\"indices\":[0,22]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":85,\"friends_count\":27,\"listed_count\":1,\"created_at\":\"Mon Sep 13 21:49:09 +0000 2010\",\"favourites_count\":0,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":true,\"verified\":false,\"statuses_count\":6008,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/1587063530\\\\/A2_copy_normal.jpg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/1587063530\\\\/A2_copy_normal.jpg\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/pQLtZO0VJd\",\"expanded_url\":\"http:\\\\/\\\\/streeteasy.com\\\\/s\\\\/550284\",\"display_url\":\"streeteasy.com\\\\/s\\\\/550284\",\"indices\":[64,86]}],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:14 +0000 2013\",\"id\":381445776742031360,\"id_str\":\"381445776742031360\",\"text\":\"Scheduled an open house for CREATE YOUR OWN 3 or 4BR GEM http:\\\\/\\\\/t.co\\\\/5EKBR8Qhou\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/www.streeteasy.com\\\\/\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eStreetEasy\\\\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\":386286589,\"id_str\":\"386286589\",\"name\":\"David Innocenzi\",\"screen_name\":\"DInnocenzi\",\"location\":\"NYC\",\"description\":\"\",\"url\":\"http:\\\\/\\\\/t.co\\\\/jvJk5gm3B6\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/jvJk5gm3B6\",\"expanded_url\":\"http:\\\\/\\\\/www.heddingsproperty.com\\\\/Agents\\\\/David-Innocenzi.aspx\",\"display_url\":\"heddingsproperty.com\\\\/Agents\\\\/David-I\\\\u2026\",\"indices\":[0,22]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":70,\"friends_count\":90,\"listed_count\":2,\"created_at\":\"Fri Oct 07 00:21:37 +0000 2011\",\"favourites_count\":0,\"utc_offset\":-14400,\"time_zone\":\"Eastern Time (US & Canada)\",\"geo_enabled\":false,\"verified\":false,\"statuses_count\":124,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"131516\",\"profile_background_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_background_images\\\\/445322315\\\\/FB_Cover.jpg\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_background_images\\\\/445322315\\\\/FB_Cover.jpg\",\"profile_background_tile\":true,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/1576087059\\\\/10_normal.jpg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/1576087059\\\\/10_normal.jpg\",\"profile_link_color\":\"009999\",\"profile_sidebar_border_color\":\"EEEEEE\",\"profile_sidebar_fill_color\":\"EFEFEF\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/5EKBR8Qhou\",\"expanded_url\":\"http:\\\\/\\\\/streeteasy.com\\\\/s\\\\/988512\",\"display_url\":\"streeteasy.com\\\\/s\\\\/988512\",\"indices\":[57,79]}],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:14 +0000 2013\",\"id\":381445775425015810,\"id_str\":\"381445775425015810\",\"text\":\"Scheduled an open house for CREATE YOUR OWN 3 or 4BR GEM http:\\\\/\\\\/t.co\\\\/DcbGEsDCpQ\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/www.streeteasy.com\\\\/\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eStreetEasy\\\\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\":14619176,\"id_str\":\"14619176\",\"name\":\"Douglas Heddings\",\"screen_name\":\"dheddings\",\"location\":\"New York, NY\",\"description\":\"Real estate broker\\\\/owner\\\\/consultant specializing in residential real estate sales and development projects in Manhattan.\",\"url\":\"http:\\\\/\\\\/t.co\\\\/Fiv6KYRVVF\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/Fiv6KYRVVF\",\"expanded_url\":\"http:\\\\/\\\\/www.heddingsproperty.com\",\"display_url\":\"heddingsproperty.com\",\"indices\":[0,22]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":1805,\"friends_count\":815,\"listed_count\":70,\"created_at\":\"Thu May 01 20:27:55 +0000 2008\",\"favourites_count\":3,\"utc_offset\":-14400,\"time_zone\":\"Eastern Time (US & Canada)\",\"geo_enabled\":true,\"verified\":false,\"statuses_count\":1672,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_background_images\\\\/192363099\\\\/twilk_background_4d2f77361da7c.jpg\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_background_images\\\\/192363099\\\\/twilk_background_4d2f77361da7c.jpg\",\"profile_background_tile\":true,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/3327932315\\\\/d8146f52c450afe6dba799c77d710812_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/3327932315\\\\/d8146f52c450afe6dba799c77d710812_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/14619176\\\\/1362227529\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/DcbGEsDCpQ\",\"expanded_url\":\"http:\\\\/\\\\/streeteasy.com\\\\/s\\\\/988512\",\"display_url\":\"streeteasy.com\\\\/s\\\\/988512\",\"indices\":[57,79]}],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:10 +0000 2013\",\"id\":381445758333231104,\"id_str\":\"381445758333231104\",\"text\":\"RT @bobmarley: Watch Bob\\'s last televised interview, filmed 33 years ago 2day in NYC during the \\'80 Uprising Tour. #TodayInBobsLife https:\\\\/\\\\u2026\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/blackberry.com\\\\/twitter\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eTwitter for BlackBerry\\\\u00ae\\\\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\":1280346516,\"id_str\":\"1280346516\",\"name\":\"Pearl_Graham\",\"screen_name\":\"ntoshlamola\",\"location\":\"Amongst the Stars\",\"description\":\"\\\\u2022Ice-cream keeps me sane_Milky Lane +Wakaberry ambassador_Xo\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":65,\"friends_count\":180,\"listed_count\":0,\"created_at\":\"Tue Mar 19 13:00:27 +0000 2013\",\"favourites_count\":4,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":false,\"statuses_count\":819,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/378800000483674474\\\\/6341fc61dcdc11c26365084d7b996863_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/378800000483674474\\\\/6341fc61dcdc11c26365084d7b996863_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/1280346516\\\\/1379679527\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweeted_status\":{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Thu Sep 19 23:02:35 +0000 2013\",\"id\":380829300767088640,\"id_str\":\"380829300767088640\",\"text\":\"Watch Bob\\'s last televised interview, filmed 33 years ago 2day in NYC during the \\'80 Uprising Tour. #TodayInBobsLife https:\\\\/\\\\/t.co\\\\/7hXu2LUTio\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/www.hootsuite.com\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eHootSuite\\\\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\":42927636,\"id_str\":\"42927636\",\"name\":\"Bob Marley\",\"screen_name\":\"bobmarley\",\"location\":\"\",\"description\":\"O N E L O V E\",\"url\":\"http:\\\\/\\\\/t.co\\\\/1gwtjdpx8X\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/1gwtjdpx8X\",\"expanded_url\":\"http:\\\\/\\\\/www.bobmarley.com\",\"display_url\":\"bobmarley.com\",\"indices\":[0,22]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":727233,\"friends_count\":22,\"listed_count\":2041,\"created_at\":\"Wed May 27 17:15:45 +0000 2009\",\"favourites_count\":4,\"utc_offset\":-25200,\"time_zone\":\"Pacific Time (US & Canada)\",\"geo_enabled\":false,\"verified\":true,\"statuses_count\":792,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"94310D\",\"profile_background_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_background_images\\\\/766498177\\\\/c46bdef6331723068fd9f30aa85dc928.gif\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_background_images\\\\/766498177\\\\/c46bdef6331723068fd9f30aa85dc928.gif\",\"profile_background_tile\":true,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/3468420961\\\\/95841c04807c60c21052bfd1c4d1d8c9_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/3468420961\\\\/95841c04807c60c21052bfd1c4d1d8c9_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/42927636\\\\/1358466054\",\"profile_link_color\":\"080707\",\"profile_sidebar_border_color\":\"000000\",\"profile_sidebar_fill_color\":\"91817F\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":212,\"favorite_count\":123,\"entities\":{\"hashtags\":[{\"text\":\"TodayInBobsLife\",\"indices\":[100,116]}],\"symbols\":[],\"urls\":[{\"url\":\"https:\\\\/\\\\/t.co\\\\/7hXu2LUTio\",\"expanded_url\":\"https:\\\\/\\\\/www.youtube.com\\\\/watch?v=WEiNixU3IY0\",\"display_url\":\"youtube.com\\\\/watch?v=WEiNix\\\\u2026\",\"indices\":[117,140]}],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},\"retweet_count\":212,\"favorite_count\":0,\"entities\":{\"hashtags\":[{\"text\":\"TodayInBobsLife\",\"indices\":[115,131]}],\"symbols\":[],\"urls\":[],\"user_mentions\":[{\"screen_name\":\"bobmarley\",\"name\":\"Bob Marley\",\"id\":42927636,\"id_str\":\"42927636\",\"indices\":[3,13]}]},\"favorited\":false,\"retweeted\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:09 +0000 2013\",\"id\":381445755829223424,\"id_str\":\"381445755829223424\",\"text\":\"Halloween must be fun in suburbia, because i consider calling out from Work in NYC.\",\"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\":158262557,\"id_str\":\"158262557\",\"name\":\"Javier Credle\",\"screen_name\":\"javiboi219\",\"location\":\"New York \\\\/ VSU\",\"description\":\"corky dude from ny, now a corky dude down south\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":350,\"friends_count\":344,\"listed_count\":1,\"created_at\":\"Tue Jun 22 06:00:28 +0000 2010\",\"favourites_count\":42,\"utc_offset\":-18000,\"time_zone\":\"Central Time (US & Canada)\",\"geo_enabled\":false,\"verified\":false,\"statuses_count\":22518,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/1583400878\\\\/Meticulous_logo1-2_normal.jpg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/1583400878\\\\/Meticulous_logo1-2_normal.jpg\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:08 +0000 2013\",\"id\":381445750984421377,\"id_str\":\"381445750984421377\",\"text\":\"Office terminal is in jersey city...I live in montville near Morristown. We can do either or I can bring truck to you as long as not NYC!!!\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/twitter.com\\\\/devices\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003etxt\\\\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\":497482360,\"id_str\":\"497482360\",\"name\":\"Jerry Langer\",\"screen_name\":\"Langer_Jerry\",\"location\":\"USA\",\"description\":\"\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":277,\"friends_count\":750,\"listed_count\":1,\"created_at\":\"Mon Feb 20 01:43:48 +0000 2012\",\"favourites_count\":77,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":true,\"verified\":false,\"statuses_count\":1734,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/3482860792\\\\/550326c74b41e9a453ced76518831c80_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/3482860792\\\\/550326c74b41e9a453ced76518831c80_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/497482360\\\\/1377558488\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:07 +0000 2013\",\"id\":381445745380843522,\"id_str\":\"381445745380843522\",\"text\":\"RT @BBM: &lt;3 #Android. BBM is coming September 21 #NYC #BBM4ALL http:\\\\/\\\\/t.co\\\\/SOSdL8CKEa\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/twitter.com\\\\/download\\\\/android\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eTwitter for Android\\\\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\":1378254385,\"id_str\":\"1378254385\",\"name\":\"M7md Al marii\",\"screen_name\":\"M7mdAlmarii\",\"location\":\"\",\"description\":\"\\\\u007b \\\\u0627\\\\u0646 \\\\u0627\\\\u0644\\\\u0644\\\\u0647 \\\\u0639\\\\u0644\\\\u0649 \\\\u0643\\\\u0644 \\\\u0634\\\\u064a\\\\u0621\\\\u064d \\\\u0642\\\\u062f\\\\u064a\\\\u0631 \\\\u007d Instgram: 7moodalmarii QATAR,DOHA\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":40,\"friends_count\":109,\"listed_count\":0,\"created_at\":\"Wed Apr 24 23:48:18 +0000 2013\",\"favourites_count\":33,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":true,\"verified\":false,\"statuses_count\":286,\"lang\":\"ar\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/3682344274\\\\/2efa1aec8bf1050c7e882347aef76bea_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/3682344274\\\\/2efa1aec8bf1050c7e882347aef76bea_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/1378254385\\\\/1372159928\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweeted_status\":{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Fri Sep 20 18:08:21 +0000 2013\",\"id\":381117643865874432,\"id_str\":\"381117643865874432\",\"text\":\"&lt;3 #Android. BBM is coming September 21 #NYC #BBM4ALL http:\\\\/\\\\/t.co\\\\/SOSdL8CKEa\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/adobe.com\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eAdobe\\\\u00ae Social\\\\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\":1676078360,\"id_str\":\"1676078360\",\"name\":\"BBM\",\"screen_name\":\"BBM\",\"location\":\"\",\"description\":\"BBM is for active, real conversations. It\\\\u2019s free, instant and always connected. Your messages are delivered and read in seconds. You trust it. You control it.\",\"url\":\"http:\\\\/\\\\/t.co\\\\/NWxI58P0p3\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/NWxI58P0p3\",\"expanded_url\":\"http:\\\\/\\\\/bbm.com\",\"display_url\":\"bbm.com\",\"indices\":[0,22]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":65877,\"friends_count\":4,\"listed_count\":255,\"created_at\":\"Fri Aug 16 16:03:55 +0000 2013\",\"favourites_count\":18,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":true,\"statuses_count\":36,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"2A6EB7\",\"profile_background_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_background_images\\\\/378800000078793339\\\\/8e2d1f6ca7d83b97d63f03100d93a53c.png\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_background_images\\\\/378800000078793339\\\\/8e2d1f6ca7d83b97d63f03100d93a53c.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/378800000474891492\\\\/a932befd66398bf513d31a3f6038a27b_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/378800000474891492\\\\/a932befd66398bf513d31a3f6038a27b_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/1676078360\\\\/1379714873\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"FFFFFF\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":3654,\"favorite_count\":494,\"entities\":{\"hashtags\":[{\"text\":\"Android\",\"indices\":[6,14]},{\"text\":\"NYC\",\"indices\":[43,47]},{\"text\":\"BBM4ALL\",\"indices\":[48,56]}],\"symbols\":[],\"urls\":[],\"user_mentions\":[],\"media\":[{\"id\":381117643731656704,\"id_str\":\"381117643731656704\",\"indices\":[57,79],\"media_url\":\"http:\\\\/\\\\/pbs.twimg.com\\\\/media\\\\/BUoAekxCYAA037B.jpg\",\"media_url_https\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/media\\\\/BUoAekxCYAA037B.jpg\",\"url\":\"http:\\\\/\\\\/t.co\\\\/SOSdL8CKEa\",\"display_url\":\"pic.twitter.com\\\\/SOSdL8CKEa\",\"expanded_url\":\"http:\\\\/\\\\/twitter.com\\\\/BBM\\\\/status\\\\/381117643865874432\\\\/photo\\\\/1\",\"type\":\"photo\",\"sizes\":{\"thumb\":{\"w\":150,\"h\":150,\"resize\":\"crop\"},\"large\":{\"w\":1024,\"h\":696,\"resize\":\"fit\"},\"medium\":{\"w\":600,\"h\":408,\"resize\":\"fit\"},\"small\":{\"w\":340,\"h\":231,\"resize\":\"fit\"}}}]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},\"retweet_count\":3654,\"favorite_count\":0,\"entities\":{\"hashtags\":[{\"text\":\"Android\",\"indices\":[15,23]},{\"text\":\"NYC\",\"indices\":[52,56]},{\"text\":\"BBM4ALL\",\"indices\":[57,65]}],\"symbols\":[],\"urls\":[],\"user_mentions\":[{\"screen_name\":\"BBM\",\"name\":\"BBM\",\"id\":1676078360,\"id_str\":\"1676078360\",\"indices\":[3,7]}],\"media\":[{\"id\":381117643731656704,\"id_str\":\"381117643731656704\",\"indices\":[66,88],\"media_url\":\"http:\\\\/\\\\/pbs.twimg.com\\\\/media\\\\/BUoAekxCYAA037B.jpg\",\"media_url_https\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/media\\\\/BUoAekxCYAA037B.jpg\",\"url\":\"http:\\\\/\\\\/t.co\\\\/SOSdL8CKEa\",\"display_url\":\"pic.twitter.com\\\\/SOSdL8CKEa\",\"expanded_url\":\"http:\\\\/\\\\/twitter.com\\\\/BBM\\\\/status\\\\/381117643865874432\\\\/photo\\\\/1\",\"type\":\"photo\",\"sizes\":{\"thumb\":{\"w\":150,\"h\":150,\"resize\":\"crop\"},\"large\":{\"w\":1024,\"h\":696,\"resize\":\"fit\"},\"medium\":{\"w\":600,\"h\":408,\"resize\":\"fit\"},\"small\":{\"w\":340,\"h\":231,\"resize\":\"fit\"}},\"source_status_id\":381117643865874432,\"source_status_id_str\":\"381117643865874432\"}]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:06 +0000 2013\",\"id\":381445743292059648,\"id_str\":\"381445743292059648\",\"text\":\"RT @HeffronDrive: \\\\\"This is my view of NYC\\\\\"\\\\n:)\\\\n#NYC\\\\n#wwDoP http:\\\\/\\\\/t.co\\\\/ZHJhzjG4Tm\",\"source\":\"web\",\"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\":295142362,\"id_str\":\"295142362\",\"name\":\"btr is forever.\",\"screen_name\":\"schmidtdimples\",\"location\":\"\\\\u2661 James\\\\/4 \\\\u2661\",\"description\":\"\\\\u262f big time rush and books \\\\u262f\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":8379,\"friends_count\":7148,\"listed_count\":14,\"created_at\":\"Sun May 08 13:01:59 +0000 2011\",\"favourites_count\":276,\"utc_offset\":-10800,\"time_zone\":\"Santiago\",\"geo_enabled\":true,\"verified\":false,\"statuses_count\":36227,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"000000\",\"profile_background_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_background_images\\\\/378800000073520978\\\\/736ea0c39bb42670cb85de6d23304827.png\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_background_images\\\\/378800000073520978\\\\/736ea0c39bb42670cb85de6d23304827.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/378800000484210443\\\\/e30e0a93e547b23f95dcfd55bd6d4fd2_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/378800000484210443\\\\/e30e0a93e547b23f95dcfd55bd6d4fd2_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/295142362\\\\/1379710799\",\"profile_link_color\":\"000000\",\"profile_sidebar_border_color\":\"FFFFFF\",\"profile_sidebar_fill_color\":\"EFEFEF\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweeted_status\":{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:09:01 +0000 2013\",\"id\":381434900991447040,\"id_str\":\"381434900991447040\",\"text\":\"\\\\\"This is my view of NYC\\\\\"\\\\n:)\\\\n#NYC\\\\n#wwDoP http:\\\\/\\\\/t.co\\\\/ZHJhzjG4Tm\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/instagram.com\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eInstagram\\\\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\":29898542,\"id_str\":\"29898542\",\"name\":\"Kendall Schmidt\",\"screen_name\":\"HeffronDrive\",\"location\":\"\",\"description\":\"Enjoy Heffron Drive \\\\nThis is The Official Kendall Schmidt Twitter. I\\'m in the band @BigTimeRush \\\\nInfo:\\\\nhttp:\\\\/\\\\/t.co\\\\/R0zwSimvtO\\\\nhttp:\\\\/\\\\/t.co\\\\/a7HSHZoMUd\",\"url\":null,\"entities\":{\"description\":{\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/R0zwSimvtO\",\"expanded_url\":\"http:\\\\/\\\\/Www.Bigtimetour.com\\\\/events\",\"display_url\":\"Bigtimetour.com\\\\/events\",\"indices\":[103,125]},{\"url\":\"http:\\\\/\\\\/t.co\\\\/a7HSHZoMUd\",\"expanded_url\":\"http:\\\\/\\\\/smarturl.it\\\\/24seven\",\"display_url\":\"smarturl.it\\\\/24seven\",\"indices\":[126,148]}]}},\"protected\":false,\"followers_count\":1865569,\"friends_count\":615,\"listed_count\":8146,\"created_at\":\"Thu Apr 09 02:35:33 +0000 2009\",\"favourites_count\":9,\"utc_offset\":-25200,\"time_zone\":\"Pacific Time (US & Canada)\",\"geo_enabled\":false,\"verified\":true,\"statuses_count\":5586,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"000000\",\"profile_background_image_url\":\"http:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme14\\\\/bg.gif\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme14\\\\/bg.gif\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/378800000231515114\\\\/1b75355717f7cfdbfb9999eceb365e79_normal.jpeg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/378800000231515114\\\\/1b75355717f7cfdbfb9999eceb365e79_normal.jpeg\",\"profile_banner_url\":\"https:\\\\/\\\\/pbs.twimg.com\\\\/profile_banners\\\\/29898542\\\\/1375465120\",\"profile_link_color\":\"FF0000\",\"profile_sidebar_border_color\":\"FFFFFF\",\"profile_sidebar_fill_color\":\"000000\",\"profile_text_color\":\"ABB9BF\",\"profile_use_background_image\":false,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":981,\"favorite_count\":906,\"entities\":{\"hashtags\":[{\"text\":\"NYC\",\"indices\":[28,32]},{\"text\":\"wwDoP\",\"indices\":[33,39]}],\"symbols\":[],\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/ZHJhzjG4Tm\",\"expanded_url\":\"http:\\\\/\\\\/instagram.com\\\\/p\\\\/eht-kHGCD3\\\\/\",\"display_url\":\"instagram.com\\\\/p\\\\/eht-kHGCD3\\\\/\",\"indices\":[40,62]}],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},\"retweet_count\":981,\"favorite_count\":0,\"entities\":{\"hashtags\":[{\"text\":\"NYC\",\"indices\":[46,50]},{\"text\":\"wwDoP\",\"indices\":[51,57]}],\"symbols\":[],\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/ZHJhzjG4Tm\",\"expanded_url\":\"http:\\\\/\\\\/instagram.com\\\\/p\\\\/eht-kHGCD3\\\\/\",\"display_url\":\"instagram.com\\\\/p\\\\/eht-kHGCD3\\\\/\",\"indices\":[58,80]}],\"user_mentions\":[{\"screen_name\":\"HeffronDrive\",\"name\":\"Kendall Schmidt\",\"id\":29898542,\"id_str\":\"29898542\",\"indices\":[3,16]}]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"},{\"metadata\":{\"result_type\":\"recent\",\"iso_language_code\":\"en\"},\"created_at\":\"Sat Sep 21 15:52:06 +0000 2013\",\"id\":381445742206132224,\"id_str\":\"381445742206132224\",\"text\":\"Scheduled an open house for Atelier Sales Office- Call 212-563-6635 http:\\\\/\\\\/t.co\\\\/bucy4P73W5\",\"source\":\"\\\\u003ca href=\\\\\"http:\\\\/\\\\/www.streeteasy.com\\\\/\\\\\" rel=\\\\\"nofollow\\\\\"\\\\u003eStreetEasy\\\\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\":190407775,\"id_str\":\"190407775\",\"name\":\"Atelier Condos Sales\",\"screen_name\":\"Ateliercondos\",\"location\":\"New York City\",\"description\":\"Atelier Condo sales and rentals. Call us at 212-563-6635. We offer luxury furnished units for a 3 month min.\",\"url\":\"http:\\\\/\\\\/t.co\\\\/PCxxSxhwRC\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/PCxxSxhwRC\",\"expanded_url\":\"http:\\\\/\\\\/www.youtube.com\\\\/watch?v=bfSKvULE5l4\",\"display_url\":\"youtube.com\\\\/watch?v=bfSKvU\\\\u2026\",\"indices\":[0,22]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":85,\"friends_count\":27,\"listed_count\":1,\"created_at\":\"Mon Sep 13 21:49:09 +0000 2010\",\"favourites_count\":0,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":true,\"verified\":false,\"statuses_count\":6008,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_image_url_https\":\"https:\\\\/\\\\/abs.twimg.com\\\\/images\\\\/themes\\\\/theme1\\\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\\\/\\\\/a0.twimg.com\\\\/profile_images\\\\/1587063530\\\\/A2_copy_normal.jpg\",\"profile_image_url_https\":\"https:\\\\/\\\\/si0.twimg.com\\\\/profile_images\\\\/1587063530\\\\/A2_copy_normal.jpg\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[{\"url\":\"http:\\\\/\\\\/t.co\\\\/bucy4P73W5\",\"expanded_url\":\"http:\\\\/\\\\/streeteasy.com\\\\/s\\\\/690754\",\"display_url\":\"streeteasy.com\\\\/s\\\\/690754\",\"indices\":[68,90]}],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"}],\"search_metadata\":{\"completed_in\":0.019,\"max_id\":381445787013906432,\"max_id_str\":\"381445787013906432\",\"next_results\":\"?max_id=381445742206132223&q=nyc&lang=en&count=10&include_entities=1\",\"query\":\"nyc\",\"refresh_url\":\"?since_id=381445787013906432&q=nyc&lang=en&include_entities=1\",\"count\":10,\"since_id\":0,\"since_id_str\":\"0\"}}'"
}
],
"prompt_number": 23
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Whoa, that's a lot of stuff in there! This looks like a very long Python String. "
},
{
"cell_type": "code",
"collapsed": false,
"input": "type(text)",
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"text": "str"
}
],
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Though, if we look closely we see that there seems to some kind of structure in which this response has been returned. There is some use of use of braces <b>{</b> and <b>}</b> and quotes <b>\"</b> and colons<b>:</b> \n \nNow this looks awfully similar to some kind of Python Dictionary stored in the form of a string. \n\nIf we go to Twitter's Search API link at https://dev.twitter.com/docs/api/1.1/get/search/tweets, on the right hand side, under the <b>Resource Information</b> section, we see that the <b>Response Format</b> is <b>json</b>. So the long string that we see above is infact a JSON object in the form of a string. \n \nPython, has a way to conveniently handle JSON objects. Python's standard libary contains a module called <a href=\"http://docs.python.org/2/library/json.html\">json</a> which allows us to handle json objects. Let us import this json module "
},
{
"cell_type": "code",
"collapsed": false,
"input": "import json",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "markdown",
"metadata": {},
"source": "We can read in the response we got from Twitter and parse that string as a JSON object using the <b>json.loads()</b> function. Let us store the result in a variable called say, <em>j</em>"
},
{
"cell_type": "code",
"collapsed": false,
"input": "j = json.loads(text)",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 24
},
{
"cell_type": "markdown",
"metadata": {},
"source": "JSON's format looks very similar to Python's Dictionary format. So let us try to see if we can access the json object similar to how we access a Python Dictionary. We noticed above that there was some kind of <em>key</em> called <b>statuses</b> which seems to be storing some <a href=\"https://dev.twitter.com/docs/platform-objects/tweets\">Tweet</a> objects as mentioned in Twitter's API Documentation at https://dev.twitter.com/docs/platform-objects/tweets "
},
{
"cell_type": "code",
"collapsed": false,
"input": "j['statuses']",
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 25,
"text": "[{'contributors': None,\n 'coordinates': None,\n 'created_at': 'Sat Sep 21 15:52:17 +0000 2013',\n 'entities': {'hashtags': [{'indices': [46, 50], 'text': 'NYC'},\n {'indices': [51, 57], 'text': 'wwDoP'}],\n 'symbols': [],\n 'urls': [{'display_url': 'instagram.com/p/eht-kHGCD3/',\n 'expanded_url': 'http://instagram.com/p/eht-kHGCD3/',\n 'indices': [58, 80],\n 'url': 'http://t.co/ZHJhzjG4Tm'}],\n 'user_mentions': [{'id': 29898542,\n 'id_str': '29898542',\n 'indices': [3, 16],\n 'name': 'Kendall Schmidt',\n 'screen_name': 'HeffronDrive'}]},\n 'favorite_count': 0,\n 'favorited': False,\n 'geo': None,\n 'id': 381445787013906432,\n 'id_str': '381445787013906432',\n 'in_reply_to_screen_name': None,\n 'in_reply_to_status_id': None,\n 'in_reply_to_status_id_str': None,\n 'in_reply_to_user_id': None,\n 'in_reply_to_user_id_str': None,\n 'lang': 'en',\n 'metadata': {'iso_language_code': 'en', 'result_type': 'recent'},\n 'place': None,\n 'possibly_sensitive': False,\n 'retweet_count': 981,\n 'retweeted': False,\n 'retweeted_status': {'contributors': None,\n 'coordinates': None,\n 'created_at': 'Sat Sep 21 15:09:01 +0000 2013',\n 'entities': {'hashtags': [{'indices': [28, 32], 'text': 'NYC'},\n {'indices': [33, 39], 'text': 'wwDoP'}],\n 'symbols': [],\n 'urls': [{'display_url': 'instagram.com/p/eht-kHGCD3/',\n 'expanded_url': 'http://instagram.com/p/eht-kHGCD3/',\n 'indices': [40, 62],\n 'url': 'http://t.co/ZHJhzjG4Tm'}],\n 'user_mentions': []},\n 'favorite_count': 906,\n 'favorited': False,\n 'geo': None,\n 'id': 381434900991447040,\n 'id_str': '381434900991447040',\n 'in_reply_to_screen_name': None,\n 'in_reply_to_status_id': None,\n 'in_reply_to_status_id_str': None,\n 'in_reply_to_user_id': None,\n 'in_reply_to_user_id_str': None,\n 'lang': 'en',\n 'metadata': {'iso_language_code': 'en', 'result_type': 'recent'},\n 'place': None,\n 'possibly_sensitive': False,\n 'retweet_count': 981,\n 'retweeted': False,\n 'source': '<a href=\"http://instagram.com\" rel=\"nofollow\">Instagram</a>',\n 'text': '\"This is my view of NYC\"\\n:)\\n#NYC\\n#wwDoP http://t.co/ZHJhzjG4Tm',\n 'truncated': False,\n 'user': {'contributors_enabled': False,\n 'created_at': 'Thu Apr 09 02:35:33 +0000 2009',\n 'default_profile': False,\n 'default_profile_image': False,\n 'description': \"Enjoy Heffron Drive \\nThis is The Official Kendall Schmidt Twitter. I'm in the band @BigTimeRush \\nInfo:\\nhttp://t.co/R0zwSimvtO\\nhttp://t.co/a7HSHZoMUd\",\n 'entities': {'description': {'urls': [{'display_url': 'Bigtimetour.com/events',\n 'expanded_url': 'http://Www.Bigtimetour.com/events',\n 'indices': [103, 125],\n 'url': 'http://t.co/R0zwSimvtO'},\n {'display_url': 'smarturl.it/24seven',\n 'expanded_url': 'http://smarturl.it/24seven',\n 'indices': [126, 148],\n 'url': 'http://t.co/a7HSHZoMUd'}]}},\n 'favourites_count': 9,\n 'follow_request_sent': False,\n 'followers_count': 1865569,\n 'following': False,\n 'friends_count': 615,\n 'geo_enabled': False,\n 'id': 29898542,\n 'id_str': '29898542',\n 'is_translator': False,\n 'lang': 'en',\n 'listed_count': 8146,\n 'location': '',\n 'name': 'Kendall Schmidt',\n 'notifications': False,\n 'profile_background_color': '000000',\n 'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme14/bg.gif',\n 'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme14/bg.gif',\n 'profile_background_tile': False,\n 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/29898542/1375465120',\n 'profile_image_url': 'http://a0.twimg.com/profile_images/378800000231515114/1b75355717f7cfdbfb9999eceb365e79_normal.jpeg',\n 'profile_image_url_https': 'https://si0.twimg.com/profile_images/378800000231515114/1b75355717f7cfdbfb9999eceb365e79_normal.jpeg',\n 'profile_link_color': 'FF0000',\n 'profile_sidebar_border_color': 'FFFFFF',\n 'profile_sidebar_fill_color': '000000',\n 'profile_text_color': 'ABB9BF',\n 'profile_use_background_image': False,\n 'protected': False,\n 'screen_name': 'HeffronDrive',\n 'statuses_count': 5586,\n 'time_zone': 'Pacific Time (US & Canada)',\n 'url': None,\n 'utc_offset': -25200,\n 'verified': True}},\n 'source': '<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Mobile Web (M2)</a>',\n 'text': 'RT @HeffronDrive: \"This is my view of NYC\"\\n:)\\n#NYC\\n#wwDoP http://t.co/ZHJhzjG4Tm',\n 'truncated': False,\n 'user': {'contributors_enabled': False,\n 'created_at': 'Fri May 31 08:43:48 +0000 2013',\n 'default_profile': False,\n 'default_profile_image': False,\n 'description': \"I'm 15.I LOVE GOD. I'm Polish Rusher. I love Logan. I like Heffron Drive, Victoria Justice, Max Schneider, Demi Lovato, Ariana Grande. I like volleyball.\",\n 'entities': {'description': {'urls': []}},\n 'favourites_count': 249,\n 'follow_request_sent': False,\n 'followers_count': 119,\n 'following': False,\n 'friends_count': 220,\n 'geo_enabled': False,\n 'id': 1471657284,\n 'id_str': '1471657284',\n 'is_translator': False,\n 'lang': 'pl',\n 'listed_count': 0,\n 'location': 'Poland',\n 'name': 'Klaudia Henderson',\n 'notifications': False,\n 'profile_background_color': '0099B9',\n 'profile_background_image_url': 'http://a0.twimg.com/profile_background_images/378800000007487043/4946bcfd1472c808559e0ae4d61d3ab8.jpeg',\n 'profile_background_image_url_https': 'https://si0.twimg.com/profile_background_images/378800000007487043/4946bcfd1472c808559e0ae4d61d3ab8.jpeg',\n 'profile_background_tile': True,\n 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/1471657284/1376756246',\n 'profile_image_url': 'http://a0.twimg.com/profile_images/378800000313539558/6af56672153afd8c7574e565f9f0dbf7_normal.png',\n 'profile_image_url_https': 'https://si0.twimg.com/profile_images/378800000313539558/6af56672153afd8c7574e565f9f0dbf7_normal.png',\n 'profile_link_color': '0099B9',\n 'profile_sidebar_border_color': '000000',\n 'profile_sidebar_fill_color': 'DDEEF6',\n 'profile_text_color': '333333',\n 'profile_use_background_image': True,\n 'protected': False,\n 'screen_name': 'KlaudiaRusher',\n 'statuses_count': 519,\n 'time_zone': 'Athens',\n 'url': None,\n 'utc_offset': 10800,\n 'verified': False}},\n {'contributors': None,\n 'coordinates': None,\n 'created_at': 'Sat Sep 21 15:52:16 +0000 2013',\n 'entities': {'hashtags': [],\n 'symbols': [],\n 'urls': [{'display_url': 'streeteasy.com/s/550284',\n 'expanded_url': 'http://streeteasy.com/s/550284',\n 'indices': [64, 86],\n 'url': 'http://t.co/pQLtZO0VJd'}],\n 'user_mentions': []},\n 'favorite_count': 0,\n 'favorited': False,\n 'geo': None,\n 'id': 381445784216285185,\n 'id_str': '381445784216285185',\n 'in_reply_to_screen_name': None,\n 'in_reply_to_status_id': None,\n 'in_reply_to_status_id_str': None,\n 'in_reply_to_user_id': None,\n 'in_reply_to_user_id_str': None,\n 'lang': 'en',\n 'metadata': {'iso_language_code': 'en', 'result_type': 'recent'},\n 'place': None,\n 'possibly_sensitive': False,\n 'retweet_count': 0,\n 'retweeted': False,\n 'source': '<a href=\"http://www.streeteasy.com/\" rel=\"nofollow\">StreetEasy</a>',\n 'text': 'Scheduled an open house for Atelier Sales Office - 212-563-6635 http://t.co/pQLtZO0VJd',\n 'truncated': False,\n 'user': {'contributors_enabled': False,\n 'created_at': 'Mon Sep 13 21:49:09 +0000 2010',\n 'default_profile': True,\n 'default_profile_image': False,\n 'description': 'Atelier Condo sales and rentals. Call us at 212-563-6635. We offer luxury furnished units for a 3 month min.',\n 'entities': {'description': {'urls': []},\n 'url': {'urls': [{'display_url': u'youtube.com/watch?v=bfSKvU\\u2026',\n 'expanded_url': 'http://www.youtube.com/watch?v=bfSKvULE5l4',\n 'indices': [0, 22],\n 'url': 'http://t.co/PCxxSxhwRC'}]}},\n 'favourites_count': 0,\n 'follow_request_sent': False,\n 'followers_count': 85,\n 'following': False,\n 'friends_count': 27,\n 'geo_enabled': True,\n 'id': 190407775,\n 'id_str': '190407775',\n 'is_translator': False,\n 'lang': 'en',\n 'listed_count': 1,\n 'location': 'New York City',\n 'name': 'Atelier Condos Sales',\n 'notifications': False,\n 'profile_background_color': 'C0DEED',\n 'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png',\n 'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png',\n 'profile_background_tile': False,\n 'profile_image_url': 'http://a0.twimg.com/profile_images/1587063530/A2_copy_normal.jpg',\n 'profile_image_url_https': 'https://si0.twimg.com/profile_images/1587063530/A2_copy_normal.jpg',\n 'profile_link_color': '0084B4',\n 'profile_sidebar_border_color': 'C0DEED',\n 'profile_sidebar_fill_color': 'DDEEF6',\n 'profile_text_color': '333333',\n 'profile_use_background_image': True,\n 'protected': False,\n 'screen_name': 'Ateliercondos',\n 'statuses_count': 6008,\n 'time_zone': None,\n 'url': 'http://t.co/PCxxSxhwRC',\n 'utc_offset': None,\n 'verified': False}}]"
}
],
"prompt_number": 25
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Alright, looks like we reading something with a definite structure now. Looks like the Tweet objects are being stored in a list, notice the <b>[</b> and <b>]</b>. Also we notice the the Tweet text is being stored in some key called <b>text</b>. \n \nCool, now we know that the Tweets are being stored in a Python <em>list</em> and the Tweet text is being stored in a key-value pair with the key called <b>text</b>. Let us go ahead and print our Tweet texts."
},
{
"cell_type": "code",
"collapsed": false,
"input": "for tweet in j['statuses']:\n print tweet['text']",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "RT @HeffronDrive: \"This is my view of NYC\"\n:)\n#NYC\n#wwDoP http://t.co/ZHJhzjG4Tm\nScheduled an open house for Atelier Sales Office - 212-563-6635 http://t.co/pQLtZO0VJd\nScheduled an open house for CREATE YOUR OWN 3 or 4BR GEM http://t.co/5EKBR8Qhou\nScheduled an open house for CREATE YOUR OWN 3 or 4BR GEM http://t.co/DcbGEsDCpQ\nRT @bobmarley: Watch Bob's last televised interview, filmed 33 years ago 2day in NYC during the '80 Uprising Tour. #TodayInBobsLife https:/\u2026\nHalloween must be fun in suburbia, because i consider calling out from Work in NYC.\nOffice terminal is in jersey city...I live in montville near Morristown. We can do either or I can bring truck to you as long as not NYC!!!\nRT @BBM: &lt;3 #Android. BBM is coming September 21 #NYC #BBM4ALL http://t.co/SOSdL8CKEa\nRT @HeffronDrive: \"This is my view of NYC\"\n:)\n#NYC\n#wwDoP http://t.co/ZHJhzjG4Tm\nScheduled an open house for Atelier Sales Office- Call 212-563-6635 http://t.co/bucy4P73W5\n"
}
],
"prompt_number": 26
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Let us go ahead and put all what we did above in a function called <em><b>printTweets()</b></em> in our <em>search.py</em> module. \n \nThe function takes as input, a variable called <em>query</em> \n\n1. Create a params dictionary which contains query and language\n2. Call <em>fetchsamples</em> with those parameters\n3. Parse the response as JSON\n4. Print the Tweet Text\n5. Save the Tweet Text in a Python list \n6. Return the list"
},
{
"cell_type": "code",
"collapsed": false,
"input": "def printTweets(query):\n params = { \n\t\t\t'q':query,\n\t\t\t'lang' : 'en',\n }\n \n # A list to store the Tweet text string\n text = []\n\n response = fetchsamples(params)\n data = response.read()\n j = json.loads(data)\n tweets = j['statuses']\n for tweet in tweets:\n\ttext.append(tweet['text'])\n\tprint tweet['text']\n\t\n return text",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
@fabimobi
Copy link

Android

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment