-
Notifications
You must be signed in to change notification settings - Fork 0
/
event (copy).py
55 lines (44 loc) · 1.64 KB
/
event (copy).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
import time
import pickle
from pathlib import Path
class Event:
keywords = []
timestamp = None
seconds = None
body = None
title = None
location = None
identity = None
thumbs_up_users = set()
thumbs_down_users = set()
expiry = None
def __init__(self, **kwargs):#, identity, title, body, location, user, keywords_list):
self.identity = identity
self.title = str(title)
self.body = str(body)
self.location = str(location)
self.seconds = time.time()
self.keywords = keywords_list
self.timestamp = datetime.datetime.fromtimestamp(self.seconds).strftime('%Y-%m-%d %H:%M:%S')
def get_num_upvotes(self):
return len(self.thumbs_up_users)
def get_num_downvotes(self):
return len(self.thumbs_up_users)
def thumb_up(self, user_name):
self.thumbs_up_users.add(user_name)
self.thumbs_down_users.remove(user_name)
self.dump_data()
def thumb_down(self, user_name):
self.thumbs_down_users.add(user_name)
self.thumbs_up_users.remove(user_name)
self.dump_data()
def read_data(self, event_name=None):
if Path("events_db/" + str(event_name)).is_file():
data_dict = pickle.load(open("events_db/" + str(event_name), "rb"))
self.thumbs_up_users = data_dict.get("thumbups")
self.thumbs_down_users = data_dict.get("thumbdowns")
#self.attendees = data_dict.get("attendees")
def dump_data(self):
data_dict = dict()
data_dict["thumbups"] = self.thumbs_up_users
data_dict["thumbdowns"] = self.thumbs_down_users