summaryrefslogtreecommitdiff
path: root/wowarmopy/calendar.py
blob: ae0348c1e131d8506c28a9cf9ff146e03133e42b (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import datetime, time
import gamedata
import constants

class EventInvitee (object):

    id = None
    name = None
    classId = None
    raceId = None
    genderId = None
    raw_status = None
    moderator = None

    def __init__ (self, json):
        self.load_from_json (json)

    def load_from_json (self, json):
        self.id = json['id']
        self.name = json['invitee']
        self.classId = json['classId']
        self.raceId = json['raceId']
        self.genderId = json['genderId']
        self.raw_status = json['status']
        self.moderator = json['moderator']

    def get_class_name (self):
        return gamedata.classes[self.classId]
    class_name = property (get_class_name)

    def get_race_name (self):
        return gamedata.racees[self.raceId]
    race_name = property (get_race_name)

    def get_portrait_image_url (self):
        return constants.images_base + constants.images_portrait_url_pattern \
                % (self.genderId, self.raceId, self.classId)
    portrait_image = property (get_portrait_image_url)

    def get_race_image_url (self):
        return constants.images_base + constants.images_race_url_pattern \
                % (self.raceId, self.genderId)
    race_image = property (get_race_image_url)

    def get_class_image_url (self):
        return constants.images_base + constants.images_class_url_pattern \
                % self.classId
    class_image = property (get_class_image_url)


    def __repr__ (self):
       return "[%s %s %s %s : %s]" % \
                (gamedata.genders[self.genderId], gamedata.races[self.raceId],
                 gamedata.classes[self.classId], self.name.encode ("utf-8"),
                 self.raw_status.encode ("utf-8"))

class Event (object):

    id = None
    armory = None
    date = None
    summary = None
    description = None
    invitees = None
    location = None
    icon = None

    def __init__ (self, armory, json):
        self.armory = armory
        time.sleep (3)
        self.load_from_json (json)

    def load_from_json (self, json):
        self.id = json['id']
        details = self.armory.get_calendar_event_details (self.id)
        self.date = datetime.datetime.fromtimestamp (details['start'] / 1000)
        self.summary = details['summary']
        self.description = details['description']
        if "location" in details:
            self.location = details['location']
        self.icon = details['icon']
        self.invitees = [EventInvitee (invitee) for invitee in details['invites']]

    def get_icon_url (self):
        return constants.images_base + constants.images_eventicon_url_pattern % self.icon

    def __repr__ (self):
        return "[%s : %s]" % (self.date.strftime ("%d/%m/%Y %H:%M"), self.summary.encode ("utf-8"))

class Calendar (object):

    armory = None
    updated = None
    month = None
    year = None
    events = None

    def __init__ (self, armory, json):
        self.armory = armory
        self.load_from_json (json)

    def load_from_json (self, json):
        self.year = json['year']
        self.month = json['month']
        self.updated = datetime.datetime.fromtimestamp (json['now'] / 1000)
        self.events = [Event (self.armory, event) for event in json['events']]

    def __repr__ (self):
        return "[Calendar for %d/%d]" % (self.month, self.year)