# -*- 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 }) # all default parameters, instance_id = 12 (free)
# If the screenshot is already in cache, it could be finished already. Othwewise, wait longer
while screenshot['status'] != 'finished' and screenshot['status'] != 'error':
  print "Wait..."
  time.sleep(10)
  screenshot = browshot.screenshot_info(screenshot['id'])

# You can request multiple thumbnails of the same screenshot at no cost
# Get a thumbnail at 1/3 (33%) of the original
browshot.screenshot_thumbnail_file(screenshot['id'], "google-1.png", { 'zoom': 33 })
print "Thumbnail saved to google-1.png"

# Get a thumbnail with a height of 100 pixels
browshot.screenshot_thumbnail_file(screenshot['id'], "google-2.png", { 'height': 100 })
print "Thumbnail saved to google-2.png"

# Get a thumbnail of 200 by 100 pixels at most
browshot.screenshot_thumbnail_file(screenshot['id'], "google-3.png", { 'height': 100, 'width': 200 })
print "Thumbnail saved to google-3.png"

# Crop the screenshot to 768x768, scale it to a 300x300 thumbnail
browshot.screenshot_thumbnail_file(screenshot['id'], "google-4.png", { 'right': 768, 'bottom': 768, 'height': 300, 'width': 300, 'ratio': 'fit' })
print "Thumbnail saved to google-4.png"