Example #1
0
def check(count=1):

    # get attachments from number of files
    attachments = mail.get_attachments(config.imap, count)
    recognized_text = []
    if attachments:
        for attachment in attachments:
            # get sender and batch of files
            sender = attachment[0][0]
            files = attachment[1]
            print("Checking letter from {}. Number of attachments: {}".format(
                sender, len(files)))
            if files:
                for file in files:
                    text = ocr.image_to_text(file)
                    recognized_text.append(text)
            else:
                mail.send_mail(config.smtp, sender, mail.messages['not found'])
                print("No files in mail. Email sent to {}".format(sender))

            if len(recognized_text) == len(files):
                for text in recognized_text:
                    # new_reciept = db.Reciept()
                    # new_reciept.id = text
                    # new_reciept.add()
                    print("Got some text:\n{}".format(text))
            else:
                mail.send_mail(config.smtp, sender, mail.messages['undefined'])
    else:
        print("No mails")
Example #2
0
def fb_data(token):
    print('access')
    print(str(token))
    re = 'https://graph.facebook.com/v3.2/me/posts?fields=comments%2Cmessage%2Cfull_picture&access_token=' + token
    me1 = requests.get(re)
    # f1 =requests.get(friends)

    data = me1.json()
    json_array = json.dumps(data)
    a = json.loads(json_array)
    store_list = []
    print(a['data'])

    for item in a['data']:

        try:
            image_url = item['full_picture']
            store_list.append(image_url)
        except KeyError:
            print("Haven't full picture")

    image = ocr.url_to_image(store_list[5])
    text = ocr.image_to_text(image)
    mc.data_predict(text)
    print(text)

    return jsonify(store_list)
Example #3
0
def manage_invoice():
    request_data = request.get_json()
    urls=[
        {
            'url' : request_data['url']
        }
    ]
    print(urls[0]['url'])
    cred = credentials.Certificate("credentials.json")
    #firebase_admin.initialize_app(cred)

    # Fetch the service account key JSON file contents
    #cred = credentials.Certificate("credentials.json")

    # Initialize the app with a service account, granting admin privileges
    app = firebase_admin.initialize_app(cred, {
        'storageBucket': 'assets-bills.appspot.com',
    }, name='storage')

    bucket = storage.bucket(app=app)
    blob = bucket.blob(urls[0]['url'])

    x=(blob.generate_signed_url(datetime.timedelta(seconds=1000), method='GET'))

    #webbrowser.open(x)

    urllib.request.urlretrieve(x, "firebasetest.jpg")

    filename=ocr.image_to_text("test.png")

    address=add.get_string(filename) #params: filename

    string=ocr.send_string("test.png")

    details=sp.get_details(string)
    return jsonify(details)
    #If command line arguments given then in reset mode
    reset = False
    if len(sys.argv) > 1:
        reset = True

    for transaction in transactions:

        if (reset):
            client.add_junk_data_receipt(transaction)
        else:
            id = monzotools.getImageID(transaction)

            if (id not in usedImages):

                url = monzotools.getImageURL(transaction)
                parsed_image = ocr.image_to_text(url)
                items = receipt_parser.parsereceipt(parsed_image)
                receipt = monzotools.genReceipt(transaction, [], items)

                #get VAT
                vatNo = receipt_parser.findVAT(parsed_image)

                if vatNo != None:
                    vatamount = int(transaction["amount"] * -0.2)
                    vat = [receipt_types.Tax("VAT", vatamount, "GBP", vatNo)]
                    receipt = monzotools.genReceipt(transaction, vat, items)

                client.add_receipt_data(transaction, receipt)
                usedImages.append(id)
    if (reset == True):
        break
import ocr
import receipt_parser

parsedimage = ocr.image_to_text("https://i.imgur.com/h8yyhst.jpg")
print(parsedimage)
parsedtext = receipt_parser.parsereceipt(parsedimage)
print(parsedtext)
print(receipt_parser.findVAT(parsedimage))
    def tesseractAnalysis(self):
        self.botRestart = tk.Button(self.root, width=12, height=4, bd=4, 
            font=('arial', 14, 'bold'), text="RE-CAPTURE", 
            activebackground="cyan", bg="cyan")
        self.botRestart.grid(row=12, column=18, pady=20)
        self.botRestart.configure(command=restart_program)   
        self.vs.set(cv2.CAP_PROP_FRAME_WIDTH,640)
        self.vs.set(cv2.CAP_PROP_FRAME_HEIGHT,260)

        self.patient_details = {}

        # extract OCR data as dict, barcode
        image = ocr.load_image(bilder)   # set image from file or capture here
        text, barcode = ocr.image_to_text(image)
        # if no text/barcode found return for another frame or iamge
        if text is None or barcode is None: return

        if text['npid'] == barcode:
            print('OCR is Okay')
        else:
            print('OCR is Poor')

        text_display = '\n'.join((text['name'],
                        ' '.join((text['npid'], text['date'], text['sex'])),
                                  text['addr']))

        name = text['name'].split(' ')
        if   len(name) > 2:
            self.patient_details['first_name']  = name[0]
            self.patient_details['middle_name'] = name[1]
            self.patient_details['last_name']   = name[2]
        elif len(name) > 1:
            self.patient_details['first_name']  = name[0]
            self.patient_details['middle_name'] = ''
            self.patient_details['last_name']   = name[1]
        else:
            self.patient_details['first_name']  = name[0]
            self.patient_details['middle_name'] = ''
            self.patient_details['last_name']   = ''

        self.patient_details['npid']    = text['npid']
        self.patient_details['dob']     = text['date']
        self.patient_details['gender']  = text['sex']
        self.patient_details['address'] = text['addr']

        #addr = text['addr'].split(', ')
        #if len(address) > 1:
        #  self.patient_details['district'] = addr[0]
        #  self.patient_details['village']  = addr[1]
        #else:
        #  self.patient_details['district'] = addr[0]
        #  self.patient_details['village']  = ''

        ocr_text_tkinter = tk.StringVar()
        ocr_text_tkinter.set(text_display)
        self.Output = tk.Label(self.root, textvariable=ocr_text_tkinter,
            font=('arial', 25, 'normal'), bg="light cyan", justify='left')
        self.Output.grid(row=12, column=4, rowspan=8, columnspan=1)
                    
        #!!Button to be changed to save function soon
        self.botSave = tk.Button(self.root, width=12, height=4, bd=4, 
            font=('arial', 14, 'bold'), text="SAVE", 
            activebackground="light blue",bg = "light green")
        self.botSave.grid(row=13, column=18)
        self.botSave.configure(command=self.save_process)