-
Notifications
You must be signed in to change notification settings - Fork 0
/
addPongTeam.pyw
76 lines (68 loc) · 2.1 KB
/
addPongTeam.pyw
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys, psycopg2, pdb
from PyQt5.QtWidgets import QDialog, QApplication
import pymsgbox
from addTeamUI import *
class MyForm(QDialog):
def __init__(self):
super().__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
password = pymsgbox.prompt("Please enter the database password: ")
conn = psycopg2.connect(host="localhost",database="arnold",user="postgres",password=password)
curs = conn.cursor()
query = """
SELECT CONCAT(first_name, ' ', last_name)
FROM players
"""
curs.execute(query)
names = curs.fetchall()
for name in names:
self.ui.comboBoxPlayer1.addItem(name[0])
self.ui.comboBoxPlayer2.addItem(name[0])
conn.commit()
conn.close()
self.ui.pushButton.clicked.connect(self.addTeam)
self.show()
def addTeam(self):
conn = psycopg2.connect(host="localhost",database="arnold",user="postgres",password="snowlep")
curs = conn.cursor()
insert_player1 = self.ui.comboBoxPlayer1.itemText(self.ui.comboBoxPlayer1.currentIndex())
player1_first_name = insert_player1.split()[0]
player1_last_name = insert_player1.split()[1]
insert_player2 = self.ui.comboBoxPlayer2.itemText(self.ui.comboBoxPlayer2.currentIndex())
player2_first_name = insert_player2.split()[0]
player2_last_name = insert_player2.split()[1]
# get player1_id
query = """
SELECT player_id
FROM players
WHERE first_name = '%s'
AND last_name = '%s'
""" % (player1_first_name, player1_last_name)
curs.execute(query)
player1_id = curs.fetchone()
# get player2_id
query = """
SELECT player_id
FROM players
WHERE first_name = '%s'
AND last_name = '%s'
""" % (player2_first_name, player2_last_name)
curs.execute(query)
player2_id = curs.fetchone()
# get team name from form
team_name = self.ui.lineEditTeamName.text()
query = """
INSERT INTO team
(team_name, player1_id, player2_id)
VALUES ('%s', '%s', '%s')
""" % (team_name, player1_id[0], player2_id[0])
curs.execute(query)
conn.commit()
conn.close()
self.ui.label.setText("Team Created, please add.")
if __name__=="__main__":
app = QApplication(sys.argv)
w = MyForm()
w.show()
sys.exit(app.exec_())