-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEvent.py
61 lines (48 loc) · 2.43 KB
/
Event.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
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
from DBSingleton import DBSingleton
class Event:
def __init__(self, event_id, away_team, home_team, sport_key, sport_title, bookmakers, commence_time, sport_group,
sport_description, participants, completed, write_to_db=False):
self.event_id = event_id
self.away_team = away_team
self.home_team = home_team
self.sport_key = sport_key
self.sport_title = sport_title
self.bookmakers = bookmakers
self.commence_time = commence_time
self.sport_group = sport_group
self.sport_description = sport_description
self._completed = completed
self._participants = {} if participants is None else participants # Format: {"user_id" : {"first_name": first_name, "amount": 0, "bet": selected_team} ..}
self.db = DBSingleton.getInstance().get_db()
self.process_new_event(write_to_db)
# if self.event_id == "725a53137d523a689adbbfb415f277a7":
# self._participants = {"5200784418": {"first_name": "Mr Badihi", "amount": 10, "bet": "New York Mets"}}
def process_new_event(self, write_to_db):
if write_to_db:
new_event_data = {
'participants': self._participants,
'away_team': self.away_team,
'home_team': self.home_team,
'sport_key': self.sport_key,
'sport_title': self.sport_title,
'bookmakers': self.bookmakers,
'commence_time': self.commence_time,
'sport_group': self.sport_group,
'sport_description': self.sport_description,
'completed': self._completed
}
self.db.write_data([f'Events/{self.event_id}', new_event_data])
def get_participants(self):
return self._participants
def set_participants(self, participants):
self._participants = participants
event_data = self.db.read_data([f'Events/{self.event_id}'])
event_data['participants'] = participants
self.db.write_data([f'Events/{self.event_id}', event_data])
def get_completed(self):
return self._completed
def set_completed(self, completed):
self._completed = completed
event_data = self.db.read_data([f'Events/{self.event_id}'])
event_data['completed'] = completed
self.db.write_data([f'Events/{self.event_id}', event_data])