forked from elliott-huge/MissionAlertBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommunityCarrierData.py
46 lines (37 loc) · 1.36 KB
/
CommunityCarrierData.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
class CommunityCarrierData:
def __init__(self, info_dict=None):
"""
Class represents a carrier object as returned from the database.
:param sqlite.Row info_dict: A single row from the sqlite query.
"""
if info_dict:
# Convert the sqlite3.Row object to a dictionary
info_dict = dict(info_dict)
else:
info_dict = dict()
self.owner_id = info_dict.get('ownerid', None)
self.channel_id = info_dict.get('channelid', None)
def to_dictionary(self):
"""
Formats the carrier data into a dictionary for easy access.
:returns: A dictionary representation for the carrier data.
:rtype: dict
"""
response = {}
for key, value in vars(self).items():
if value is not None:
response[key] = value
return response
def __str__(self):
"""
Overloads str to return a readable object
:rtype: str
"""
return 'CommunityCarrierData: OwnerID:{0.owner_id} ChannelID:{0.channel_id}'.format(self)
def __bool__(self):
"""
Override boolean to check if any values are set, if yes then return True, else False, where false is an empty
class.
:rtype: bool
"""
return any([value for key, value in vars(self).items() if value])