Открыть случайную картинку из 500px.com
- #!/usr/bin/python
- import json
- import urllib2
- import sys
- import random
- import webbrowser
- BASE_URL = "https://api.500px.com/v1/photos/"
- CONSUMER_KEY = "key from https://500px.com/settings/applications"
- JSON_URL = BASE_URL + "?consumer_key=" + CONSUMER_KEY + "&image_size=2048"
- def fetch_one():
- request = urllib2.Request(JSON_URL + "&page=%d" % random.randint(1, 1000))
- response = urllib2.urlopen(request).read()
- data = json.loads(response)
- photo = random.choice(data['photos'])
- webbrowser.open(photo['images'][0]['url'])
- if __name__ == '__main__':
- fetch_one()