Skip to content

Instantly share code, notes, and snippets.

@stephenjbarr
Created June 26, 2015 07:02
Show Gist options
  • Save stephenjbarr/234b609ca63575c55196 to your computer and use it in GitHub Desktop.
Save stephenjbarr/234b609ca63575c55196 to your computer and use it in GitHub Desktop.
Find images from a string using Duck Duck Go's API
{
"metadata": {
"name": "",
"signature": "sha256:a1d46d6db61857a10a811537203ce4f5bea4db915cb1fbd2fc9835b10e6c2a35"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import requests\n",
"import json\n",
"from IPython.display import Image"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 54
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"payload = {\"q\" : \"BBQ\",\n",
" \"format\" : \"json\",\n",
" \"pretty\" : 1}"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 59
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"r = requests.get('http://api.duckduckgo.com/', params = payload)\n",
"r.url"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 60,
"text": [
"'http://api.duckduckgo.com/?pretty=1&format=json&q=BBQ'"
]
}
],
"prompt_number": 60
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"rj = r.json()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 61
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Image(url=rj['Image'])"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<img src=\"https://duckduckgo.com/i/514f6486.jpg\"/>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 62,
"text": [
"<IPython.core.display.Image at 0x7fc6745d97b8>"
]
}
],
"prompt_number": 62
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment