-
Notifications
You must be signed in to change notification settings - Fork 0
/
observer.py
81 lines (61 loc) · 2.25 KB
/
observer.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from time import sleep
from group import Group
from member import Member
from jsonstream import Jsonstream
class Observer:
# How many groups does info panel show
# !! Warning !!
# If you change this number, you must rewrite .kv file.
show_num = 10
def __init__(self):
self.jsonstream = Jsonstream()
self.group_list = []
self.group_dict = self.jsonstream.get_group_dict()
self.convert_dict2list()
self.prev_group_dict = {}
self.new_created_group = {}
self.observing_groups = []
def convert_dict2list(self):
count = 0
self.group_list = []
for key in self.group_dict:
g = self.group_dict[key]
self.group_list.append(g)
count += 1
self.group_list.reverse()
def get_observing_group_list(self):
observing_group_list = []
for i in range(self.show_num):
dummy_member = Member(0,"",[],False,0,0,0,0)
dummy_group = Group(0,[],[dummy_member],[],0,False,0,0,0,0,0,"","")
observing_group_list.append(dummy_group)
count = 0
for g in self.group_list:
if g.group_name in self.observing_groups:
observing_group_list[count] = g
count += 1
if count >= self.show_num:
break
return observing_group_list
def get_created_attention_group_dict(self):
created_attention_group_dict = {}
self.new_created_group = {}
for key in self.group_dict:
if key not in self.prev_group_dict:
self.new_created_group[key] = self.group_dict[key]
for key in self.new_created_group:
g = self.new_created_group[key]
name = g.group_name
if name in self.observing_groups:
created_attention_group_dict[key] = g
return created_attention_group_dict
## Just for debug
def show_all_group(self):
for key in self.group_dict:
g = self.group_dict[key]
name = g.group_name
print("%d : %s" % (key, name))
def renew(self):
self.prev_group_dict = self.group_dict
self.group_dict = self.jsonstream.get_group_dict()
self.convert_dict2list()