Открыть случайную картинку из 500px.com

  1. #!/usr/bin/python
  2.  
  3. import json
  4. import urllib2
  5. import sys
  6. import random
  7. import webbrowser
  8.  
  9. BASE_URL = "https://api.500px.com/v1/photos/"
  10. CONSUMER_KEY = "key from https://500px.com/settings/applications"
  11. JSON_URL = BASE_URL + "?consumer_key=" + CONSUMER_KEY + "&image_size=2048"
  12.  
  13. def fetch_one():
  14.     request = urllib2.Request(JSON_URL + "&page=%d" % random.randint(1, 1000))
  15.     response = urllib2.urlopen(request).read()
  16.  
  17.     data = json.loads(response)
  18.     photo = random.choice(data['photos'])
  19.  
  20.     webbrowser.open(photo['images'][0]['url'])
  21.  
  22. if __name__ == '__main__':
  23.     fetch_one()
:gg:

Реклама

Мы в соцсетях

tw tg yt gt