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

from browshot import BrowshotClient
import time

browshot = BrowshotClient('my_api_key')

# Create a text file with a list of URLs
fp = open("batch.txt", mode='w')
fp.write("google.com\n")
fp.write("mobilito.net\n")
fp.close()


batch = browshot.batch_create("batch.txt", { 'instance_id': 65, 'screen_width': 1600, 'screen_height': 1200, 'size': 'page' }) # Get full size thumbnails
if batch['status'] == 'error':
  print("Batch failed: %s" % batch['error'])
  exit(0)


print "Batch #%d in process" % int(batch['id'])

time.sleep(30)
while batch['status'] != 'finished' and batch['status'] != 'error':
  time.sleep(15)
  batch = browshot.batch_info(batch['id'])


if batch['status'] == 'error':
  print("Batch failed: %s" % batch['error'])
  exit(0)

# The batch succeeded, download the archive. There may be more than 1 URL
for url in batch['urls']:
  print "Downloading %s..." % url
