Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ishu3101
Created May 29, 2017 00:58
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 ishu3101/9c238455857f7c00e895b738d11aabf4 to your computer and use it in GitHub Desktop.
Save ishu3101/9c238455857f7c00e895b738d11aabf4 to your computer and use it in GitHub Desktop.
Generate a Random Programming Quote using an API
#!/usr/bin/python
import urllib
import urllib2
import random
import json
# get a random programming quote using an api
url="http://quotes.stormconsultancy.co.uk/random.json"
request = urllib2.urlopen(url)
data = request.read()
print data
json = json.loads(data)
print json
print repr(json)
quote = json["quote"]
author = json["author"]
print quote.encode("utf-8") + " - " + author.encode("utf-8")
print quote
@Hartley2k
Copy link

the data does not work on line 13

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