def make_screenshot(view, frame): print "%d starting screenshot at %s for %s id=%s" % \ (view.fg_owner, datetime.now(), view.fg_type, view.fg_id) try: gdk_win = view.fg_browser.window (width, height) = gdk_win.get_size() pixel_buffer = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height) pixel_buffer.get_from_drawable(gdk_win, gdk_win.get_colormap(), 0, 0, 0, 0, width, height) if is_image_all_one_color(pixel_buffer): return False filepath = "%s/%s.jpg" % (TMP_DIR, view.fg_id) pixel_buffer.save(filepath, 'jpeg', {'quality': '95'}) print "%d starting save to s3 id=%s (%s)" % (view.fg_owner, view.fg_id, filepath) page_id = view.fg_task.page.id controller.save_thumb_to_s3(view.fg_task.page, filepath) if view.fg_is_webpage: view.fg_task.delete() print "%d done saving to s3 id=%s page_id=%s" % (view.fg_owner, view.fg_id, page_id) os.remove(filepath); print "%d finishing screenshot at %s for %s id=%s" % (view.fg_owner, datetime.now(), view.fg_type, view.fg_id) except: traceback.print_exc(file=sys.stdout) return False return True
def make_thumbs_for_image(task): url_io = urllib2.urlopen(task.page.source_url) content_type = url_io.headers.get('content-type') # Downloading the image from the source URL and saving it to a temporary file. temp_filepath = "%s/%s_orig.image" % (TMP_DIR, task.id) f = open(temp_filepath, 'wb') f.write(url_io.read()) f.close() controller.save_thumb_to_s3(task.page, temp_filepath) os.remove(temp_filepath) print "done saving to s3 id=%s page_id=%s" % (task.id, task.page.id)