-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageToText.py
More file actions
34 lines (32 loc) · 1.21 KB
/
imageToText.py
File metadata and controls
34 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytesseract
try:
from PIL import Image
except ImportError:
import Image
import pandas as pd
import os
from credentials import iMessageEmail,iMessagePhone
import numpy as np
import sys
def PrintImageAttachment(conn,sender):
try:
filename = str(pd.read_sql_query("select filename from attachment ORDER BY ROWID DESC limit 1", conn)['filename'][0])
os.system("cp {} test.png".format(filename))
#print(filename)
img = Image.open("test.png")
text = pytesseract.image_to_string(img)
if len(text) < 10:
exit()
print(text)
f = open("response.txt", "w")
f.write(text)
f.close()
os.system("osascript sendtxt.scpt \"{}\"".format(sender))
inform = 'osascript -e \'tell application "Messages" \n send \"Image to text complete.\" to buddy "{}" of service "E:{}" \n end tell\''.format(sender,iMessageEmail)
os.system(inform)
except Exception as e:
print("image conversion failed")
print(e)
sys.exit(1)
def isAttachment(conn):
return bool(pd.read_sql_query("select cache_has_attachments from message ORDER BY ROWID DESC limit 1", conn)["cache_has_attachments"][0])