diff --git a/janine/janine.py b/janine/janine.py index 3d53ea4..6612731 100644 --- a/janine/janine.py +++ b/janine/janine.py @@ -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() diff --git a/janine/sources.py b/janine/sources.py index 76dfa0a..dd8d4f6 100644 --- a/janine/sources.py +++ b/janine/sources.py @@ -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)) diff --git a/janine/utils.py b/janine/utils.py index 69ce535..978c063 100644 --- a/janine/utils.py +++ b/janine/utils.py @@ -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 -