forked from elliott-huge/MissionAlertBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarrierData.py
54 lines (45 loc) · 1.88 KB
/
CarrierData.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
class CarrierData:
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.carrier_long_name = info_dict.get('longname', None)
self.carrier_short_name = info_dict.get('shortname', None)
self.carrier_identifier = info_dict.get('cid', None)
self.discord_channel = info_dict.get('discordchannel', None)
self.channel_id = info_dict.get('channelid', None)
self.ownerid = info_dict.get('ownerid', None)
self.pid = info_dict.get('p_ID', 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 'CarrierData: CarrierLongName:{0.carrier_long_name} CarrierShortName:{0.carrier_short_name} ' \
'CarrierIdentifier:{0.carrier_identifier} DiscordChannel:{0.discord_channel} ' \
'DiscordChannelID:{0.channel_id} ' \
'OwnerID:{0.ownerid} CarrierPid:{0.pid}'.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])