Skip to content

Commit

Permalink
Merge pull request #249 from mbfhunzaker/master
Browse files Browse the repository at this point in the history
Unquote Twitter API responses to address URL encoding error
  • Loading branch information
ptwobrussell committed Jan 15, 2015
2 parents b2b3fad + a532e35 commit a4db107
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ipynb/Chapter 1 - Mining Twitter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@
"cell_type": "code",
"collapsed": false,
"input": [
"# Import unquote to prevent url encoding errors in next_results\n",
"from urllib import unquote\n",
"\n",
"# XXX: Set this variable to a trending topic, \n",
"# or anything else for that matter. The example query below\n",
"# was a trending topic when this content was being developed\n",
Expand Down Expand Up @@ -209,7 +212,7 @@
" \n",
" # Create a dictionary from next_results, which has the following form:\n",
" # ?max_id=313519052523986943&q=NCAA&include_entities=1\n",
" kwargs = dict([ kv.split('=') for kv in next_results[1:].split(\"&\") ])\n",
" kwargs = dict([ kv.split('=') for kv in unquote(next_results[1:]).split(\"&\") ])\n",
" \n",
" search_results = twitter_api.search.tweets(**kwargs)\n",
" statuses += search_results['statuses']\n",
Expand Down
6 changes: 5 additions & 1 deletion ipynb/__Chapter 1 - Mining Twitter (Full-Text Sampler).ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,9 @@
"cell_type": "code",
"collapsed": false,
"input": [
"# Import unquote to prevent url encoding errors in next_results\n",
"from urllib import unquote\n",
"\n",
"# XXX: Set this variable to a trending topic, \n",
"# or anything else for that matter. The example query below\n",
"# was a trending topic when this content was being developed\n",
Expand Down Expand Up @@ -1237,7 +1240,8 @@
" \n",
" # Create a dictionary from next_results, which has the following form:\n",
" # ?max_id=313519052523986943&q=NCAA&include_entities=1\n",
" kwargs = dict([ kv.split('=') for kv in next_results[1:].split(\"&\") ])\n",
" kwargs = dict([kv.split('=') for kv in unquote(next_results[1:]).split(\"&\") ]) \n",
"\n",
" \n",
" search_results = twitter_api.search.tweets(**kwargs)\n",
" statuses += search_results['statuses']\n",
Expand Down

0 comments on commit a4db107

Please sign in to comment.