From 55ed21f690aa69acce063ffb3fd3781a076e5b7d Mon Sep 17 00:00:00 2001 From: David Sterry Date: Mon, 13 Sep 2021 16:02:01 -0700 Subject: [PATCH] if nodeinfo supplies usage, check that it's a dict --- federation/hostmeta/parsers.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/federation/hostmeta/parsers.py b/federation/hostmeta/parsers.py index a2c35665..c3b9889d 100644 --- a/federation/hostmeta/parsers.py +++ b/federation/hostmeta/parsers.py @@ -208,14 +208,17 @@ def parse_nodeinfo_document(doc, host): services = sorted(list(set(inbound + outbound))) result['services'] = services result['open_signups'] = doc.get('openRegistrations', False) - result['activity']['users']['total'] = int_or_none(doc.get('usage', {}).get('users', {}).get('total')) - result['activity']['users']['half_year'] = int_or_none(doc.get('usage', {}).get('users', {}).get('activeHalfyear')) - monthly = int_or_none(doc.get('usage', {}).get('users', {}).get('activeMonth')) - result['activity']['users']['monthly'] = monthly - if monthly: - result['activity']['users']['weekly'] = int(monthly * MONTHLY_USERS_WEEKLY_MULTIPLIER) - result['activity']['local_posts'] = int_or_none(doc.get('usage', {}).get('localPosts')) - result['activity']['local_comments'] = int_or_none(doc.get('usage', {}).get('localComments')) + + if isinstance(doc.get('usage', {}), dict): + result['activity']['users']['total'] = int_or_none(doc.get('usage', {}).get('users', {}).get('total')) + result['activity']['users']['half_year'] = int_or_none(doc.get('usage', {}).get('users', {}).get('activeHalfyear')) + monthly = int_or_none(doc.get('usage', {}).get('users', {}).get('activeMonth')) + result['activity']['users']['monthly'] = monthly + if monthly: + result['activity']['users']['weekly'] = int(monthly * MONTHLY_USERS_WEEKLY_MULTIPLIER) + result['activity']['local_posts'] = int_or_none(doc.get('usage', {}).get('localPosts')) + result['activity']['local_comments'] = int_or_none(doc.get('usage', {}).get('localComments')) + result['features'] = doc.get('metadata', {}) admin_handle = doc.get('metadata', {}).get('adminAccount', None) if admin_handle: