# -*- coding: utf-8 -*-

from browshot import BrowshotClient
import time

browshot = BrowshotClient('my_api_key')


screenshot = browshot.screenshot_create('http://www.google.com/', { 'instance_id': 12, 'size': 'screen' }) # all default paramters, instance_id = 12 (free)

# If the screenshot is already in cache, it could be finished already. Otherwise, wait longer
while screenshot['status'] != 'finished' and screenshot['status'] != 'error':
  print "Wait..."
  time.sleep(10)
  screenshot = browshot.screenshot_info(screenshot['id'])

# screenshot is done: finished (sucessful) or error (failed)
if screenshot['status'] == 'error':
  print  "Screenshot failed: " + screenshot['error'] # display the reason for the error
else: # request the thumbnail
  browshot.screenshot_thumbnail_file(screenshot['id'], '/tmp/google-640.png', { 'width': 640, 'height': 480 })
  print "Screenshot was saved to /tmp/google-640.png"