-
Notifications
You must be signed in to change notification settings - Fork 0
/
ktimer.py
34 lines (26 loc) · 932 Bytes
/
ktimer.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
from pymongo import MongoClient
from kobject import KObject
class KTimer(KObject):
def __init__(self, name, char, onetime, start_time,
callback, duration, *args):
KObject.__init__(self, _id=None)
self.name = name
self.args = args
self.onetime = onetime
self.callback = callback
self.start_time = start_time
self.duration = duration
self.char = char
self._id = self.state_save()
def die(self):
self.callback(self)
def state_save(self):
client = MongoClient('mongodb://192.168.0.107:27017/')
db = client.kmud
collection = db.timers
timer = {'char': self.char._id,
'duration': self.duration,
'start': self.start_time,
'onetime': self.onetime,
'args': self.args}
return collection.insert_one(timer).inserted_id