Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys,os,pymysql
- import sys
- from PIL import Image
- import base64
- import io
- import PIL.Image
- serverip = None
- username = None
- password = None
- database = None
- conn = None
- cur = None
- def connect():
- global serverip, username, password, database, conn, cur
- serverip = input("ServerIP>")
- username = input("username>")
- password = input("password>")
- database = input("Database>")
- try:
- conn = pymysql.connect(host=serverip,user=username, password=password, db=database, charset = 'utf8mb4',autocommit=True)
- cur = conn.cursor()
- except pymysql.Error as err:
- print(err)
- print("App>DB서버연결에 실패했습니다.")
- sys.exit(1)
- def input_value(): # Input Value
- global cur
- _id = "" #input("idvl>")
- name = input("name>")
- info = input("info>")
- query = "insert into pytable (id,name,info) value('NULL','" +name+ "','" +info+ "');"
- cur.execute(query)
- def print_row(): # Print Tables
- global cur
- cur.execute("select * from pytable");
- row = cur.fetchall()
- print(row)
- def input_image() :
- f = open("/home/pi/testimg/imglist.txt",'r')
- url = "/home/pi/testimg/"
- while True:
- line = f.readline()
- if not line : break;
- tmp_g = line.split('/')
- filename = tmp_g[1]
- line = line.rstrip()
- filename = filename.rstrip()
- image = Image.open(url+line)
- blob_v = open(url+line,'rb').read()
- width, height = image.size
- size = os.path.getsize(url+line)
- print("[",filename,"/",width,"/",height,"/",size,"]")
- print("["+filename+"] uploaded")
- query = "insert into image_pixel(data,name,info,width,height,size) value(%s,'"+filename+"','"+line+"',"+str(width)+","+str(height)+","+str(size)+");"
- cur.execute(query,(blob_v,))
- f.close()
- def output_image() :
- cur.execute("select * from image_pixel")
- data=cur.fetchall()
- print(type(data[0][0]))
- file = io.BytesIO(data[0][0])
- for row in data:
- print("["+row[1]+"] Download!")
- f = open("/home/pi/downimg/"+row[1],"wb")
- f.write(row[0])
- f.close()
- #img = PIL.Image.open(file)
- #img.show()
- connect()
- print("App>",serverip ,"에 연결 성공")
- select = None
- while True:
- print("\n\nMenu>1)Input 2>Print 3>Exit")
- select = input("select>")
- if select == '' : print("App>Invalid Value")
- elif select == '1':
- input_image()
- elif select == '2':
- output_image()
- elif select == '3':
- break
- else : print("App>Invalid Value")
- conn.close()
- cur.close()
- print("App>byebye")
Add Comment
Please, Sign In to add comment