refactor: Remove dict_get_fallback
This commit is contained in:
parent
e7a3743a84
commit
4b40a65a65
@ -13,7 +13,7 @@ from aioxmpp.structs import PresenceShow
|
||||
|
||||
import requests
|
||||
|
||||
from janine.utils import find_one, find_all, dict_get_fallback
|
||||
from janine.utils import find_one, find_all
|
||||
from janine.sources import sources_from_config
|
||||
|
||||
log = logging.getLogger('janine')
|
||||
@ -36,15 +36,15 @@ def to_warning(data):
|
||||
return Warning(id=data['identifier'],
|
||||
sent=data['sent'],
|
||||
# Not all items have to have those
|
||||
effective_from=dict_get_fallback(info, 'effective', 'N/A'),
|
||||
effective_from=info.get('effective', 'N/A'),
|
||||
# Not all items have to have those
|
||||
expires=dict_get_fallback(info, 'expires', 'N/A'),
|
||||
expires=info.get('expires', 'N/A'),
|
||||
urgency=info['urgency'],
|
||||
# Not all items have to have those
|
||||
sender=dict_get_fallback(info, 'senderName', 'N/A'),
|
||||
sender=info.get('senderName', 'N/A'),
|
||||
headline=info['headline'],
|
||||
description=info['description'],
|
||||
instruction=dict_get_fallback(info, 'instruction', 'N/A'))
|
||||
instruction=info.get('instruction', 'N/A'))
|
||||
|
||||
def landkreis_filter(kreis, item):
|
||||
'''
|
||||
@ -172,7 +172,7 @@ class WarningBot:
|
||||
# Bot Config
|
||||
self._jid = aioxmpp.JID.fromstr(config['Bot']['JID'])
|
||||
self._password = config['Bot']['Password']
|
||||
self._avatar = dict_get_fallback(config['Bot'], 'Avatar', None)
|
||||
self._avatar = config['Bot'].get('Avatar', None)
|
||||
|
||||
def main():
|
||||
bot = WarningBot()
|
||||
|
@ -32,9 +32,8 @@ class WarningSources:
|
||||
def sources_from_config(config):
|
||||
sources = []
|
||||
for module in ('IHP', 'DWD', 'BIWAPP', 'MOWAS'):
|
||||
option = dict_get_fallback(config['General'],
|
||||
module,
|
||||
'n')
|
||||
option = config['General'].get(module, 'n')
|
||||
|
||||
if option == 'y':
|
||||
sources.append(WarningSources.source_by_name(module))
|
||||
|
||||
|
@ -16,12 +16,3 @@ def find_all(func, array):
|
||||
Return all elements in array for which func returns True.
|
||||
'''
|
||||
return [e for e in array if func(e)]
|
||||
|
||||
def dict_get_fallback(d, key, fallback):
|
||||
'''
|
||||
Utility function
|
||||
|
||||
Returns d[key] if key exists. Else, return fallback
|
||||
'''
|
||||
return d[key] if key in d.keys() else fallback
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user