Completed
Push — develop ( 001bd4...f2ccae )
by Wu
11s
created

PicPhotoOrAlbumEvent   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 2
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
3 15
import six
4 15
from werobot.messages.entries import StringEntry, IntEntry, FloatEntry
5
from werobot.messages.base import WeRoBotMetaClass
6 15
7
8
class EventMetaClass(WeRoBotMetaClass):
9 15
    pass
10 15
11 15
12
@six.add_metaclass(EventMetaClass)
13 15
class WeChatEvent(object):
14 15
    target = StringEntry('ToUserName')
15 15
    source = StringEntry('FromUserName')
16
    time = IntEntry('CreateTime')
17
    message_id = IntEntry('MsgID', 0)
18
19 15
    def __init__(self, message):
20 15
        self.__dict__.update(message)
21
22
23 15
class SimpleEvent(WeChatEvent):
24 15
    key = StringEntry('EventKey')
25 15
26 15
27 15
class TicketEvent(WeChatEvent):
28
    key = StringEntry('EventKey')
29 15
    ticket = StringEntry('Ticket')
30 15
31
32
class SubscribeEvent(TicketEvent):
33 15
    __type__ = 'subscribe_event'
34 15
35 15
36
class UnSubscribeEvent(WeChatEvent):
37
    __type__ = 'unsubscribe_event'
38 15
39 15
40
class ScanEvent(TicketEvent):
41
    __type__ = 'scan_event'
42 15
43 15
44
class ScanCodePushEvent(SimpleEvent):
45
    __type__ = 'scancode_push_event'
46 15
    scan_type = StringEntry('ScanCodeInfo.ScanType')
47 15
    scan_result = StringEntry('ScanCodeInfo.ScanResult')
48
49
50 15
class ScanCodeWaitMsgEvent(ScanCodePushEvent):
51 15
    __type__ = 'scancode_waitmsg_event'
52
    scan_type = StringEntry('ScanCodeInfo.ScanType')
53
    scan_result = StringEntry('ScanCodeInfo.ScanResult')
54 15
55 15
56
class BasePicEvent(SimpleEvent):
57
    count = IntEntry('SendPicsInfo.Count')
58 15
59 15
    def __init__(self, message):
60
        super(BasePicEvent, self).__init__(message)
61
        self.pic_list = list()
62 15
        if self.count > 1:
63 15
            for item in message['SendPicsInfo']['PicList'].pop('item'):
64 15
                self.pic_list.append({'pic_md5_sum': item['PicMd5Sum']})
65 15
        else:
66 15
            self.pic_list.append(
67
                {'pic_md5_sum': message['SendPicsInfo']['PicList'].pop('item')['PicMd5Sum']}
68
            )
69 15
70 15
71
class PicSysphotoEvent(BasePicEvent):
72
    __type__ = 'pic_sysphoto_event'
73
74
75
class PicPhotoOrAlbumEvent(BasePicEvent):
76
    __type__ = 'pic_photo_or_album_event'
77
78
79
class PicWeixinEvent(BasePicEvent):
80
    __type__ = 'pic_weixin_event'
81
82
83
class LocationSelectEvent(SimpleEvent):
84
    __type__ = 'location_select_event'
85
    location_x = StringEntry('SendLocationInfo.Location_X')
86
    location_y = StringEntry('SendLocationInfo.Location_Y')
87
    scale = StringEntry('SendLocationInfo.Scale')
88
    label = StringEntry('SendLocationInfo.Label')
89
    poi_name = StringEntry('SendLocationInfo.Poiname')
90
91
92
class ClickEvent(SimpleEvent):
93
    __type__ = 'click_event'
94
95
96
class ViewEvent(SimpleEvent):
97
    __type__ = 'view_event'
98
99
100
class LocationEvent(WeChatEvent):
101
    __type__ = 'location_event'
102
    latitude = FloatEntry('Latitude')
103
    longitude = FloatEntry('Longitude')
104
    precision = FloatEntry('Precision')
105
106
107
class TemplateSendJobFinishEvent(WeChatEvent):
108
    __type__ = 'templatesendjobfinish_event'
109
    status = StringEntry('Status')
110
111
112
class BaseProductEvent(WeChatEvent):
113
    key_standard = StringEntry('KeyStandard')
114
    key_str = StringEntry('KeyStr')
115
    ext_info = StringEntry('ExtInfo')
116
117
118
class UserScanProductEvent(BaseProductEvent):
119
    __type__ = 'user_scan_product_event'
120
    country = StringEntry('Country')
121
    province = StringEntry('Province')
122
    city = StringEntry('City')
123
    sex = IntEntry('Sex')
124
    scene = IntEntry('Scene')
125
126
127
class UserScanProductEnterSessionEvent(BaseProductEvent):
128
    __type__ = 'user_scan_product_enter_session_event'
129
130
131
class UserScanProductAsyncEvent(BaseProductEvent):
132
    __type__ = 'user_scan_product_async_event'
133
    region_code = StringEntry('RegionCode')
134
135
136
class UserScanProductVerifyActionEvent(WeChatEvent):
137
    __type__ = 'user_scan_product_verify_action_event'
138
    key_standard = StringEntry('KeyStandard')
139
    key_str = StringEntry('KeyStr')
140
    result = StringEntry('Result')
141
    reason_msg = StringEntry('ReasonMsg')
142
143
144
class UnknownEvent(WeChatEvent):
145
    __type__ = 'unknown_event'
146