-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDBOper.py
More file actions
51 lines (41 loc) · 1.69 KB
/
DBOper.py
File metadata and controls
51 lines (41 loc) · 1.69 KB
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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sqlite3
from player import player, PLAYER_LIST
conn = sqlite3.connect('playerInfo')
c = conn.cursor()
def init():
cursor = c.execute("SELECT * from playerInfo")
for row in cursor:
player_obj = player(short_steamID=row[0],
long_steamID=row[1],
nickname=row[2],
last_DOTA2_match_ID=row[4])
player_obj.DOTA2_score = row[4]
PLAYER_LIST.append(player_obj)
def update_DOTA2_match_ID(short_steamID, last_DOTA2_match_ID):
c.execute("UPDATE playerInfo SET last_DOTA2_match_ID='{}' "
"WHERE short_steamID={}".format(last_DOTA2_match_ID, short_steamID))
conn.commit()
def insert_info(short_steamID, long_steamID, nickname, last_DOTA2_match_ID):
c.execute("INSERT INTO playerInfo (short_steamID, long_steamID, nickname, last_DOTA2_match_ID) "
"VALUES ({}, {}, '{}', '{}')"
.format(short_steamID, long_steamID, nickname, last_DOTA2_match_ID))
conn.commit()
def is_player_stored(short_steamID: int) -> bool:
c.execute("SELECT * FROM playerInfo WHERE short_steamID=={}".format(short_steamID))
if len(c.fetchall()) == 0:
return False
return True
def get_playing_game(short_steamID):
ret = c.execute(
"SELECT gamename, last_update FROM playerInfo WHERE short_steamID=?",
(short_steamID,)
).fetchone()
return (ret[0], ret[1]) if ret else ('', 0)
def update_playing_game(short_steamID, gamename, timestamp):
c.execute(
"UPDATE playerInfo SET gamename=?, last_update=? WHERE short_steamID=?",
(gamename, timestamp, short_steamID)
)
conn.commit()