def handle_uploaded_file(f): filedir = "%s/%s" % (settings.MEDIA_ROOT, time.time()) logger.info("Step 1. Making temporary directory at %s ..." % filedir) os.mkdir(filedir) logger.info("OK") filename = "%s/%s" % (filedir, int(time.time())) logger.info("Step 2. Creating file at %s ..." % filename) with open(filename, 'wb+') as destination: for chunk in f.chunks(): destination.write(chunk) logger.info("OK") logger.info("Step 3. Running OCR on file at %s ..." % filename) try: result = tesseractlib.ocr_from_file(filename) logger.info("OK") except Exception, e: logger.error("Exception caught when running tesseract-ocr: %s" % e) result = "Error: %s" % e
def test_lib(self): filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'test.png') result = tesseractlib.ocr_from_file(filename) self.assertEqual(result, 'Tesseract-OCR')