def __call__(self): sypht = SyphtClient() print("Uploading: ", self.path, "...") with open(self.path, "rb") as f: doc_id = sypht.upload(f, self.products) print("Processing: ", doc_id, "...") print(json.dumps(sypht.fetch_results(doc_id), indent=2))
def __call__(self): sypht = SyphtClient() print('Uploading: ', self.path, '...') with open(self.path, 'rb') as f: doc_id = sypht.upload(f, self.fieldsets) print('Processing: ', doc_id, '...') print(json.dumps(sypht.fetch_results(doc_id), indent=2))
class DataExtraction(unittest.TestCase): def setUp(self): if not six.PY2: warnings.simplefilter('ignore', category=ResourceWarning) self.sypht_client = SyphtClient(os.environ['CLIENT_ID'], os.environ['CLIENT_SECRET']) def test_with_wrong_fieldset(self): with self.assertRaises(Exception) as context: with open('tests/sample_invoice.pdf', 'rb') as f: response = self.sypht_client.upload(f, fieldsets=[ 'sypht.incorrect', ]) self.assertIn( 'does not have permission to use fieldSet sypht.incorrect', reponse['error']) self.assertTrue( 'Request failed with status code' in str(context.exception)) def test_data_extraction_1(self): with open('tests/sample_invoice.pdf', 'rb') as f: fid = self.sypht_client.upload(f, fieldsets=Fieldset.INVOICE) self.assertTrue(validate_uuid4(fid)) results = self.sypht_client.fetch_results(fid) self.assertTrue(isinstance(results, dict)) self.assertIn('invoice.dueDate', results) self.assertIn('invoice.total', results) self.assertIn('invoice.amountPaid', results) self.assertIn('invoice.amountDue', results) def test_data_extraction_2(self): with open('tests/sample_invoice.pdf', 'rb') as f: fid = self.sypht_client.upload(f, fieldsets=[ Fieldset.INVOICE, Fieldset.BANK, ]) self.assertTrue(validate_uuid4(fid)) results = self.sypht_client.fetch_results(fid) self.assertTrue(isinstance(results, dict)) self.assertIn('invoice.dueDate', results) self.assertIn('invoice.total', results) self.assertIn('invoice.amountPaid', results) self.assertIn('invoice.amountDue', results) self.assertIn('bank.accountNo', results) self.assertIn('bank.bsb', results)
class DataExtraction(unittest.TestCase): def setUp(self): warnings.simplefilter("ignore", category=ResourceWarning) self.sypht_client = SyphtClient(os.environ["CLIENT_ID"], os.environ["CLIENT_SECRET"]) def test_with_wrong_fieldset(self): with self.assertRaises(Exception) as context: with open("tests/sample_invoice.pdf", "rb") as f: response = self.sypht_client.upload( f, [ "sypht.incorrect", ], ) self.assertIn( "does not have permission to use fieldSet sypht.incorrect", response["error"], ) self.assertTrue( "Request failed with status code" in str(context.exception)) def test_data_extraction_1(self): with open("tests/sample_invoice.pdf", "rb") as f: fid = self.sypht_client.upload(f, ["invoices"]) self.assertTrue(validate_uuid4(fid)) results = self.sypht_client.fetch_results(fid) self.assertTrue(isinstance(results, dict)) self.assertIn("invoice.dueDate", results) self.assertIn("invoice.total", results) self.assertIn("invoice.amountPaid", results) self.assertIn("invoice.amountDue", results) def test_data_extraction_2(self): with open("tests/sample_invoice.pdf", "rb") as f: fid = self.sypht_client.upload( f, products=["sypht.invoice", "sypht.bank"]) self.assertTrue(validate_uuid4(fid)) results = self.sypht_client.fetch_results(fid) self.assertTrue(isinstance(results, dict)) self.assertIn("invoice.dueDate", results) self.assertIn("invoice.total", results) self.assertIn("invoice.amountPaid", results) self.assertIn("invoice.amountDue", results) self.assertIn("bank.accountNo", results) self.assertIn("bank.bsb", results) def test_parent_doc_id(self): parent_doc_id = uuid4() with open("tests/sample_invoice.pdf", "rb") as f: fid = self.sypht_client.upload(f, ["invoices"], parent_doc_id=parent_doc_id) self.assertTrue(validate_uuid4(fid))
class ReauthenticateTest(unittest.TestCase): def setUp(self): self.sypht_client = SyphtClient() self.init_access_token = str(self.sypht_client._access_token) self.assertFalse(self.sypht_client._is_token_expired()) def test_no_reauthentication(self): # Test non-expired token doesn't require reauthentication self.sypht_client.get_company() self.assertEqual(self.init_access_token, self.sypht_client._access_token) def test_reauthentication(self): # Set auth expiry to 1 second ago to avoid mocking datetime self.sypht_client._auth_expiry = datetime.utcnow() - timedelta(seconds=1) self.assertTrue(self.sypht_client._is_token_expired()) # Get request will auto-reauthenticate. self.sypht_client.get_company() self.assertFalse(self.sypht_client._is_token_expired())
from sypht.client import SyphtClient, Fieldset ##sypht clientid,secretkey can be obtained by registering in sypht.com scc = SyphtClient( 'JNSJgJF3SEltPf11DZLtdPE9SFPdrmlh', '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••') import os ###importing libraries import pandas as pd #give path of receipts folder to extract there dates folder = r"C:\Users\..\Downloads\Desktop\syphtclient\Receipts" dates = [] filenames = [] for filename in os.listdir(folder): print(filename) #jpgfile = Image.open(os.path.join(folder, filename)) with open(os.path.join(folder, filename), 'rb') as f: fid = scc.upload( f, fieldsets=["document"] ) ###obtaining results by uploading image on sypht through sypht api key f.close() ab = scc.fetch_results(fid) ###fetching results print(scc.fetch_results(fid)) filenames.append(filename) if not ab: ###check the dictionary is empty or not #print('none') dates.append('none') else: dates.append(ab['document.date'])
from flask import Flask, request, redirect, url_for, render_template, jsonify from werkzeug.utils import secure_filename from sypht.client import SyphtClient, Fieldset ##sypht is used to extract insights data for all types of files #import matplotlib.image as plt #import requests import os app = Flask(__name__) #from io import BytesIO #from PIL import Image ##give a folder to store uploaded images app.config['UPLOAD_FOLDER'] = 'static/' ##sypht clientid,secretkey can be obtained by registering in sypht.com ##please enter your own secretkey as i replaced my secretkey with dots for security reasons... scc = SyphtClient( 'JNSJgJF3SEltPf11DZLtdPE9SFPdrmlh', '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••') @app.route('/', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': # Check if the post request has the file part if 'file' not in request.files: print('No file part') return redirect(request.url) #if file: file = request.files['file'] filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) ##saving file into folder
# get the ratio between average shadow pixels and average lit pixels ratio_as_al = average_ld / average_le # added these difference for i in range(y_cb_cr_img.shape[0]): for j in range(y_cb_cr_img.shape[1]): if erosion[i, j, 0] == 255 and erosion[i, j, 1] == 255 and erosion[i, j, 2] == 255: y_cb_cr_img[i, j] = [ y_cb_cr_img[i, j, 0] + i_diff, y_cb_cr_img[i, j, 1] + ratio_as_al, y_cb_cr_img[i, j, 2] + ratio_as_al ] # covert the YCbCr image to the BGR image final_image = cv2.cvtColor(y_cb_cr_img, cv2.COLOR_YCR_CB2BGR) cv2.imwrite('images/new-{}'.format(image_filename), final_image) from sypht.client import SyphtClient, Fieldset scc = SyphtClient('JNSJgJF3SEltPf11DZLtdPE9SFPdrmlh', '......................................................') with open('images/new-{}'.format(image_filename), 'rb') as f: fid = scc.upload(f, fieldsets=["document"]) print(scc.fetch_results(fid)) cv2.imshow("im1", or_img) cv2.imshow("im2", final_image) cv2.waitKey(0) cv2.destroyAllWindows()
def setUp(self): self.sypht_client = SyphtClient() self.init_access_token = str(self.sypht_client._access_token) self.assertFalse(self.sypht_client._is_token_expired())
def setUp(self): warnings.simplefilter("ignore", category=ResourceWarning) self.sypht_client = SyphtClient(os.environ["CLIENT_ID"], os.environ["CLIENT_SECRET"])
def setUp(self): if not six.PY2: warnings.simplefilter('ignore', category=ResourceWarning) self.sypht_client = SyphtClient(os.environ['CLIENT_ID'], os.environ['CLIENT_SECRET'])
documents in a watched directory according to the extracted date and \ supplier name. The date and supplier ABN are extracted using the Sypht \ API, and the supplier name is derrived from the ABN using the \ Australian Business Register's web services.") parser.add_argument("config", help="the configuration file") args = parser.parse_args() config = configparser.ConfigParser() config.read(args.config) logging.basicConfig(filename=config.get("Logging", "Output"), filemode="a", level=config.get("Logging", "Level"), format=LOG_FMT) sypht_client = SyphtClient(config.get("APIs", "Sypht_CID"), config.get("APIs", "Sypht_Secret")) abr_client = ABRClient(config.get("APIs", "ABR_GUID")) event_handler = SyphtFSEventHandler(sypht_client, abr_client, config.get("Directories", "Output")) observer = Observer() observer.schedule(event_handler, config.get("Directories", "Input")) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() event_handler.stop() observer.join()