-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.py
35 lines (26 loc) · 855 Bytes
/
read.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
import datetime
import subprocess as sp
import pymysql
import pymysql.cursors
from tabulate import tabulate # pip install tabulate
def print_query(query, cur, con):
try:
#print(f"QUERY IS {query}")
cur.execute(query)
con.commit()
result = cur.fetchall()
if len(result) != 0:
header = result[0].keys()
rows = [x.values() for x in result]
print(tabulate(rows, header, tablefmt = 'psql'))
else:
print("Not found!") #length of result is 0
except Exception as e:
print(e)
con.rollback()
input("Press any key to continue")
def read_data(cur, con, table_name):
#print("inside " + table_name)
query = "select * from `" + table_name +"`;"
print_query(query, cur, con)
#table_name = "`Airport`