# -*- coding: utf-8 -*-
#######################
# WARNING
# Running this code sample will cost you Browshot credits
#######################

from browshot import BrowshotClient
import time

browshot = BrowshotClient('my_api_key', 1) # more debug information


list = browshot.screenshot_multiple({ 'urls': ['http://www.google.com/', 'https://browshot.com/', 'http://mobilito.net/'], 'instances': [12, 24, 72], 'size': 'page' }) # up to 5 URLs

time.sleep(20)
ids = list.keys() #  hold all screenshot IDs


while len(ids) > 0: # go through each screenshot
  i = 0
  while i < len(ids):
    id = ids[i]
    
    info = browshot.screenshot_info(id)
    if info['status'] == 'finished':
      browshot.screenshot_thumbnail_file(id, "%s.png" % id)
      del ids[i] # remove ID from the list
    elif info['status'] == 'error':
      print "Screenshot failed: %s\n" % info['error']
      print "\tURL: %s\n", info['url']
      print "\tinstance_id: %s\n" % info['instance_id']
      print "\n"
      
      del ids[i] # remove ID from the list
    else:
      # wait
      i += 1
  
  
  if len(ids) > 0:
    time.sleep(10)