forked from lakshmi-21/Gagnant-Bytes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getdata.py
55 lines (52 loc) · 1.52 KB
/
getdata.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
# Importing the 'cgi' module
import cgi
import cgitb
cgitb.enable()
import mysql.connector
from mysql.connector import Error
from PIL import Image
from pytesser import *
def write_file(data, filename):
with open(filename, 'wb') as f:
f.write(data)
def read_blob(author_id, filename):
# select photo column of a specific author
query = "Select img from final where id = %s;"
args=(author_id,)
#args=(author_id)
connection = mysql.connector.connect(host="localhost", user="root1", passwd="", database="college")
try:
# query blob data form the authors table
cursor = connection.cursor()
cursor.execute(query, args)
photo = cursor.fetchone()[0]
#print("photo name ")
#print(photo)
# write blob data into a file
write_file(photo, filename)
# upload_file(author_id,filename,photo)
except Error as e:
print(e)
finally:
cursor.close()
connection.close()
def main(uid):
s="file"+str(uid)+".tif"
read_blob(uid,s)
image_file = s
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
#print("Content-type: text/html\r\n\r\n")
print("<html><body>")
#print("<h1> Hello Program! </h1>")
return text
#n1=text.find("Name :")
#n1=n1+6
#print(n1)
#print(text[n1:11])
print("</body></html>")
if __name__ == '__main__':
main()