-
Notifications
You must be signed in to change notification settings - Fork 0
/
Votes.py
44 lines (30 loc) · 975 Bytes
/
Votes.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
import json
import JSONEncoderExt
from threading import Timer
import Config
import ServerCommunication
import logging
log = logging.getLogger("Votes")
class Vote:
messageId = ""
isUpvote = False
def __init__(self, message_id, is_upvote):
self.messageId = message_id
self.isUpvote = is_upvote
def repr_json(self):
return dict(messageId=self.messageId, isUpvote=self.isUpvote)
votes = []
def add_vote(message_id, is_upvote):
vote = Vote(message_id, is_upvote)
votes.append(vote)
def clear_votes():
log.info("Clearing votes array")
del votes[:]
def get_json():
# return json.dumps(votes, cls=JSONEncoderExt.ComplexEncoder, indent=4, separators=(',', ': '))
return json.dumps(votes, cls=JSONEncoderExt.ComplexEncoder)
def post_votes():
# submit votes every X seconds, default every 2 minutes
t = Timer(Config.vote_post_frequency, post_votes)
t.start()
ServerCommunication.post_votes()