def __init__(self): self._dbConnect = DBConnect() self._root = Tk() tv = ttk.Treeview(self._root) tv.pack() tv.heading("#0", text="ID") tv.configure(column=('Name', 'Gender', 'Comment')) tv.heading("Name", text='Full Name') tv.heading("Gender", text='Gender') tv.heading("Comment", text='Comment') cursor = self._dbConnect.listInfo() for row in cursor: tv.insert('', 'end', '#{}'.format(row["ID"]), text=row["ID"]) tv.set('#{}'.format(row["ID"]), 'Name', row["FullName"]) tv.set('#{}'.format(row["ID"]), 'Gender', row["Gender"]) tv.set('#{}'.format(row["ID"]), 'Comment', row["Comment"]) def deleteButton(): delRecord = deleteRecord() delButton = ttk.Button(self._root, text='Delete') delButton.pack() delButton.config(command=deleteButton) self._root.mainloop()
def continues(self): a = str(self.txtid.get()) b = str(self.txtname.get()) c = str(self.txtmeter.get()) d = str(self.txtward.get()) e = str(self.txthousetax.get()) f = str(self.txthealthtax.get()) g = str(self.txtlighttax.get()) h = str(self.txtwatertax.get()) i = str(self.txttotal.get()) database = DBConnect(host='localhost', user='******', password='******', database='etax2019') new_user = { 'idnumber': a, 'meternumber': c, 'wardnumber': d, 'name': b, 'housetax': e, 'healthtax': f, 'lighttax': g, 'watertax': h, 'total': i } database.insert(new_user, 'kalamwadiinfo') tkinter.messagebox.showinfo('etax-2019', 'Data was entered successfully')
def delete_student(id): db = DBConnect() result = db.execute("DELETE FROM students WHERE id='{}'".format(id)) response_object = {'method': 'deleted {}'.format(id)} db.close() return json.dumps(response_object)
def setUp(self): """Prepare for Test.""" environment = os.environ.get('CI_ENV', "local") if environment == "local": self.database = DBConnect('test/test_credentials.json') elif environment == "Gitlab": self.database = DBConnect('test/gitlab_credentials.json') elif environment == "Travis": self.database = DBConnect('test/travis_credentials.json')
class dbTest(TestCase): def setUp(self): """ Prepare for Test """ self.database = DBConnect('travis_credentials.json') def tearDown(self): """ Finish Testing """ # Delete all created rows self.database.cursor.execute("truncate test") self.database.commit() # Disconnect from database self.database.disconnect() def test_insert(self): """ Test inserting information into database """ new_user = { 'name': 'Emin Mastizada', 'email': '*****@*****.**', 'views': 6, } result = self.database.insert(new_user, 'test') self.assertTrue(result["status"], "Insert Failed with message %s" % result["message"]) def test_commit(self): """ Test committing all users at once """ for user in USERS: result = self.database.insert(user, 'test', commit=False) self.assertTrue(result["status"], "Insert Failed with message %s" % result["message"]) self.database.commit() # Now there should be 3 users in table with views=0 result = self.database.fetch( 'test', fields=['count(id)'], filters={'views': 0} ) self.assertTrue(len(result), "Fetch returned empty results") if len(result): self.assertTrue('count(id)' in result[0].keys(), "Requested field 'count(id)' missing in result keys") if 'count(id)' in result[0].keys(): self.assertEqual(result[0]['count(id)'], 3, "Number of new users in table should be 3") def test_fetch(self): """ Test fetching information from database """ pass
class dbTest(TestCase): def setUp(self): """ Prepare for Test """ self.database = DBConnect('travis_credentials.json') def tearDown(self): """ Finish Testing """ # Delete all created rows self.database.cursor.execute("truncate test") self.database.commit() # Disconnect from database self.database.disconnect() def test_insert(self): """ Test inserting information into database """ new_user = { 'name': 'Emin Mastizada', 'email': '*****@*****.**', 'views': 6, } result = self.database.insert(new_user, 'test') self.assertTrue(result["status"], "Insert Failed with message %s" % result["message"]) def test_commit(self): """ Test committing all users at once """ for user in USERS: result = self.database.insert(user, 'test', commit=False) self.assertTrue( result["status"], "Insert Failed with message %s" % result["message"]) self.database.commit() # Now there should be 3 users in table with views=0 result = self.database.fetch('test', fields=['count(id)'], filters={'views': 0}) self.assertTrue(len(result), "Fetch returned empty results") if len(result): self.assertTrue( 'count(id)' in result[0].keys(), "Requested field 'count(id)' missing in result keys") if 'count(id)' in result[0].keys(): self.assertEqual(result[0]['count(id)'], 3, "Number of new users in table should be 3") def test_fetch(self): """ Test fetching information from database """ pass
def update_student(id): request_data = get_request_data(request) if len(request_data) == 0: return json.dumps({'error': 'no data'}) db = DBConnect() result = db.execute("UPDATE students SET {} WHERE id='{}'".format(to_string(request_data), id)) response_object = {'method': 'updated {}'.format(id)} db.close() return json.dumps(response_object)
def __init__(self): self._dbConnect = DBConnect() self._root = Tk() ttk.Label(self._root, text='Enter ID to delete: ').grid(row=0, column=0, pady=10, padx=10) entry = ttk.Entry(self._root, width=30, font=('Arial', 14)) entry.grid(row=0, column=1) delButton = ttk.Button(self._root, text='Delete') delButton.grid(row=0, column=2) def delete(): idEntry = int(entry.get()) self._dbConnect.deleteRecord(idEntry) entry.delete() messagebox.showinfo(title="Record deleted", message="Record with ID {} was successfully deleted!".format(idEntry)) delButton.config(command=delete)
def add_student(): request_data = get_request_data(request) if len(request_data) == 0: return json.dumps({'error': 'no data'}) db = DBConnect() values = ( request_data.get('name'), request_data.get('phone'), request_data.get('email'), request_data.get('address'), ) result = db.execute("INSERT INTO students (name, phone, email, address) VALUES (%s,%s,%s,%s)", values) response_object = {'method': 'created {}'.format(id)} db.close() return json.dumps(response_object)
def setUp(self): """Prepare for Test.""" environment = os.environ.get('CI_ENV', "local") if environment == "local": self.database = DBConnect('test/test_credentials.json') elif environment == "Gitlab": self.database = DBConnect('test/gitlab_credentials.json') elif environment == "Travis": self.database = DBConnect('test/travis_credentials.json')
def insert(type1, ammount1): ''' type1 --> str ammount1 --> integer ''' database = DBConnect(host=hostname, user=MYSQLusername, password=MYSQLpass, database=dbname) new_user = {'type': type1, 'ammount': ammount1} database.insert(new_user, 'Maintainance') database.commit()
def insert(year1,month1,day1,type1,ammount1): ''' year1 --> integer month1 --> integer day1 --> integer type1 --> str ammount1 --> integer ''' database = DBConnect(host=hostname,user=MYSQLusername,password=MYSQLpass, database=dbname) new_user = {'year': year1,'month': month1,'day': day1,'type': type1,'ammount': ammount1} database.insert(new_user,'Expences') database.commit()
def insert(fname1, lname1, Role1, exp1, salary1, att_today1, att_total1): ''' fname1 --> str lname1 --> str Role1 --> str exp1 --> int salary1 --> integer att_today1 --> integer att_total1 --> integer ''' database = DBConnect(host=hostname,user=MYSQLusername,password=MYSQLpass, database=dbname) new_user = {'fname' : fname1, 'lname' : lname1, 'Role' : Role1, 'exp' : exp1, 'salary' : salary1, 'att_today' : att_today1, 'att_total' : att_total1} database.insert(new_user,'workers') database.commit()
def submit4(self): a=str(self.txt_idnumber.get()); b=str(self.txt_name.get()); c=str(self.txt_meternumber.get()); d=str(self.txt_wardnumber.get()); e=str(self.txt_house.get()); f=str(self.txt_health.get()); g=str(self.txt_light.get()); h=str(self.txt_water.get()); i=str(self.txt_total.get()); j=str(self.txt_reciept.get()); k=str(self.txt_housepaid.get()); l=str(self.txt_healthpaid.get()); m=str(self.txt_lightpaid.get()); n=str(self.txt_waterpaid.get()); o=str(self.txt_totalpaid.get()); v=str(self.txt_village.get()); localtime=str(time.asctime(time.localtime(time.time()))) t=int(i) u=int(o) p=str(t-u) database = DBConnect(host='localhost',user='******',password='******',database='etax2019') new_user = {'village':v,'idnumber': a,'meternumber': c,'wardnumber': d,'name': b,'housetax': e,'healthtax': f,'lighttax': g,'watertax': h,'total': i,'reciptnumber':j,'housetaxpaid':k,'healthtaxpaid':l,'lighttaxpaid':m,'watertaxpaid':n,'totalpaid':o,'rest':p} database.insert(new_user,'updateddata') database.commit() content1="WARNING !!!!!! \n\n\n Hi there is a New request to modify eTAX 2019 database \n Here are details: \n Village Name : "+v+"\n\n" content2="\nReciept Number :"+j+"\nName :"+b+"\nID Number :"+a+"\nMeter Number :"+c+"\nWard Number :"+d+"\nHouse Tax :"+e+"\nHealth Tax :"+f+"\nLight Tax :"+g+"\nWater Tax :"+h+"\nTotal Ammount of tax to be paid :"+i+"\nPaid House Tax :"+k+"\nPaid Health Tax :"+l+"\nPaid Light Tax :"+m+"\nPiad Water Tax :"+n+"\nTotal Tax paid :"+o totcontaint=content1+content2 mail= smtplib.SMTP('smtp.gmail.com',587) mail.ehlo() mail.starttls() mail.login('*****@*****.**','Pass@123') mail.sendmail('*****@*****.**','*****@*****.**',totcontaint) mail.close() messagebox.showinfo("etax-2019","Data Deleted Successfully") root.destroy()
def setUp(self): """ Prepare for Test """ self.database = DBConnect('travis_credentials.json')
class DBTest(TestCase): def setUp(self): """Prepare for Test.""" environment = os.environ.get('CI_ENV', "local") if environment == "local": self.database = DBConnect('test/test_credentials.json') elif environment == "Gitlab": self.database = DBConnect('test/gitlab_credentials.json') elif environment == "Travis": self.database = DBConnect('test/travis_credentials.json') def tearDown(self): """Finish Testing.""" # Delete all created rows self.database.cursor.execute("truncate test") self.database.commit() # Disconnect from database self.database.disconnect() def test_insert(self): """Test inserting information into database.""" new_user = { 'name': 'Emin Mastizada', 'email': '*****@*****.**', 'views': 6, } result = self.database.insert(new_user, 'test') self.assertTrue(result["status"], "Insert Failed with message %s" % result["message"]) def test_commit(self): """Test committing all users at once.""" for user in USERS: result = self.database.insert(user, 'test', commit=False) self.assertTrue(result["status"], "Insert Failed with message %s" % result["message"]) self.database.commit() # Now there should be 3 users in table with views=0 result = self.database.fetch( 'test', fields=['count(id)'], filters={'views': 0} ) self.assertTrue(len(result), "Fetch returned empty results") if len(result): self.assertTrue('count(id)' in result[0].keys(), "Requested field 'count(id)' missing in result keys") if 'count(id)' in result[0].keys(): self.assertEqual(result[0]['count(id)'], 3, "Number of new users in table should be 3") def test_fetch(self): """Test fetching information from database.""" pass def test_sum(self): """Test value_sum functionality.""" counter = 1 for user in USERS[:3]: user['views'] = counter self.database.insert(user, 'test') counter += 1 sum_result = self.database.value_sum( 'test', fields=['views'] ) # views = 1 + 2 + 3 = 6 self.assertEqual( sum_result['views'], 6, "Sum of 3 new users should be 6" )
class DBTest(TestCase): def setUp(self): """Prepare for Test.""" environment = os.environ.get('CI_ENV', "local") if environment == "local": self.database = DBConnect('test/test_credentials.json') elif environment == "Gitlab": self.database = DBConnect('test/gitlab_credentials.json') elif environment == "Travis": self.database = DBConnect('test/travis_credentials.json') def tearDown(self): """Finish Testing.""" # Delete all created rows self.database.cursor.execute("truncate test") self.database.commit() # Disconnect from database self.database.disconnect() def test_insert(self): """Test inserting information into database.""" new_user = { 'name': 'Emin Mastizada', 'email': '*****@*****.**', 'views': 6, } result = self.database.insert(new_user, 'test') self.assertTrue(result["status"], "Insert Failed with message %s" % result["message"]) def test_commit(self): """Test committing all users at once.""" for user in USERS: result = self.database.insert(user, 'test', commit=False) self.assertTrue( result["status"], "Insert Failed with message %s" % result["message"]) self.database.commit() # Now there should be 3 users in table with views=0 result = self.database.fetch('test', fields=['count(id)'], filters={'views': 0}) self.assertTrue(len(result), "Fetch returned empty results") if len(result): self.assertTrue( 'count(id)' in result[0].keys(), "Requested field 'count(id)' missing in result keys") if 'count(id)' in result[0].keys(): self.assertEqual(result[0]['count(id)'], 3, "Number of new users in table should be 3") def test_fetch(self): """Test fetching information from database.""" pass def test_sum(self): """Test value_sum functionality.""" counter = 1 for user in USERS[:3]: user['views'] = counter self.database.insert(user, 'test') counter += 1 sum_result = self.database.value_sum('test', fields=['views']) # views = 1 + 2 + 3 = 6 self.assertEqual(sum_result['views'], 6, "Sum of 3 new users should be 6")
# from bs4 import BeautifulSoup from DBModels import JsonData from dbConnect import DBConnect import pandas as pd import json global session def add_json(json_file): with open(json_file) as f: json_input = json.load(f) for i in json_input: d = JsonData(id = i['thread_id'], json_data = i) session.add(d) session.commit() if __name__ == '__main__': config_file = "configuration.json" json_file = "json_outputs.json" global session # get connection engine and session db_connect = DBConnect() db_connect.start_db(config_file) engine = db_connect.get_engine() session = db_connect.get_session() add_json(json_file)
def submit5(self): a = str(self.txt_idnumber.get()) b = str(self.txt_name.get()) c = str(self.txt_meternumber.get()) d = str(self.txt_wardnumber.get()) e = str(self.txt_house.get()) f = str(self.txt_health.get()) g = str(self.txt_light.get()) h = str(self.txt_water.get()) i = str(self.txt_total.get()) j = str(self.txt_reciept.get()) k = str(self.txt_housepaid.get()) l = str(self.txt_healthpaid.get()) m = str(self.txt_lightpaid.get()) n = str(self.txt_waterpaid.get()) o = str(self.txt_totalpaid.get()) v = str(self.txt_village.get()) localtime = str(time.asctime(time.localtime(time.time()))) t = int(i) u = int(o) p = str(t - u) mydb = mysql.connector.connect(host='localhost', user='******', passwd='Pass@123', database='etax2019') mycursor = mydb.cursor() query = ("DELETE from updateddata where idnumber = %s" % (a)) mycursor.execute(query) mydb.commit() mydb = mysql.connector.connect(host='localhost', user='******', passwd='Pass@123', database='etax2019') mycursor = mydb.cursor() query = ("DELETE from %s where idnumber = %s" % (v, a)) mycursor.execute(query) mydb.commit() database = DBConnect(host='localhost', user='******', password='******', database='etax2019') new_user = { 'village': v, 'idnumber': a, 'meternumber': c, 'wardnumber': d, 'name': b, 'housetax': e, 'healthtax': f, 'lighttax': g, 'watertax': h, 'total': i, 'reciptnumber': j, 'housetaxpaid': k, 'healthtaxpaid': l, 'lighttaxpaid': m, 'watertaxpaid': n, 'totalpaid': o, 'rest': p } database.insert(new_user, 'updateddataper') mydb.commit() database = DBConnect(host='localhost', user='******', password='******', database='etax2019') new_user = { 'idnumber': a, 'meternumber': c, 'wardnumber': d, 'name': b, 'housetax': e, 'healthtax': f, 'lighttax': g, 'watertax': h, 'total': i, 'reciptnumber': j, 'housetaxpaid': k, 'healthtaxpaid': l, 'lighttaxpaid': m, 'watertaxpaid': n, 'totalpaid': o, 'rest': p } database.insert(new_user, v) mydb.commit() messagebox.showinfo("etax-2019", "Data Deleted Successfully")
from tkinter import * from tkinter import ttk from tkinter import messagebox from dbConnect import DBConnect from listReservation import listUsers dbConnect = DBConnect() root = Tk() root.configure(background='#015692') root.title('Reservation') #style style = ttk.Style() style.theme_use('classic') style.configure('TLabel', background='#015692', foreground='white') style.configure('TButton', background='#015692', foreground='white') style.configure('TRadiobutton', background='#015692', foreground='white') ttk.Label(root, text='Full name: ').grid(row=0, column=0, pady=10, padx=10) ttk.Label(root, text='Gender: ').grid(row=1, column=0) ttk.Label(root, text='Comment: ').grid(row=2, column=0) etFullName = ttk.Entry(root, width=30, font=('Arial', 14)) etFullName.grid(row=0, column=1, columnspan=3, pady=10) spanGender = StringVar() spanGender.set('Male') ttk.Radiobutton(root, text='Male', variable=spanGender, value='Male').grid(row=1, column=1) ttk.Radiobutton(root, text='Female', variable=spanGender,
def get_student(id): db = DBConnect() result = db.query("SELECT * FROM students WHERE id='{}'".format(id)) db.close() return json.dumps(result)
def get_students(): db = DBConnect() result = db.query("SELECT * FROM students") db.close() return json.dumps(result)
def setUp(self): """ Prepare for Test """ self.database = DBConnect('travis_credentials.json')
def connect_db(): """ Connects to database :return: DBConnect database """ return DBConnect('credentials.json')