# HG changeset patch # User Dennis Fink # Date 2015-10-22 17:25:15 # Node ID 98d80dfbd7e36e17ea3e0a48ece992b154594465 # Parent dd4694e8752c84f9bfbb0f94d7cbb8600f1189be Don't fail on calculation weights for relays Relays don't have a 5_years subkey in their weights json. We fix this by using a try clause and simply continue with the next iteration if a key is missing diff --git a/ennstatus/api/model.py b/ennstatus/api/model.py --- a/ennstatus/api/model.py +++ b/ennstatus/api/model.py @@ -36,7 +36,11 @@ def calculate_weight(data): for subkey in ('1_week', '1_month', '3_months', '1_year', '5_years'): - subdata = data[subkey] + try: + subdata = data[subkey] + except KeyError: + continue + factor = subdata['factor'] values = [x * factor for x in subdata['values'] if x is not None]