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

from browshot import BrowshotClient
import time

browshot = BrowshotClient('my_api_key')


crawl = browshot.crawl_create("blitapp.com", "https://blitapp.com/", { 'instance_id': 65, 'screen_width': 1600, 'screen_height': 1200, 'size': 'page' }) # Get full size thumbnails
if crawl['status'] == 'error':
  print("Crawl failed: %s" % crawl['error'])
  exit(0)


print "Crawl #%d in process" % int(crawl['id'])

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


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

# The crawl succeeded, download the thumbnails
for screenshot in batch['urls']:
  print "Downloading screenshot %s..." % screenshot.id
  browshot.screenshot_thumbnail_file(screenshot['id'], "file.png", { 'right': 768, 'bottom': 768, 'height': 300, 'width': 300, 'ratio': 'fit' })
