From 4f1f9bf1ce84b4a114b895074fc3659f28069a40 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 15 Dec 2017 23:46:47 +0100 Subject: [PATCH] Fixed errors on unknown genders --- fbchat/__init__.py | 2 +- fbchat/client.py | 4 ++-- fbchat/graphql.py | 2 +- fbchat/utils.py | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/fbchat/__init__.py b/fbchat/__init__.py index a144829..2e2e08e 100644 --- a/fbchat/__init__.py +++ b/fbchat/__init__.py @@ -17,7 +17,7 @@ from .client import * __copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year) -__version__ = '1.1.2' +__version__ = '1.1.3' __license__ = 'BSD' __author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart' __email__ = 'carpedm20@gmail.com' diff --git a/fbchat/client.py b/fbchat/client.py index 68b2425..4161fea 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -479,7 +479,7 @@ class Client(object): if k['id'] in ['0', 0]: # Skip invalid users pass - users.append(User(k['id'], first_name=k.get('firstName'), url=k.get('uri'), photo=k.get('thumbSrc'), name=k.get('name'), is_friend=k.get('is_friend'), gender=GENDERS[k.get('gender')])) + users.append(User(k['id'], first_name=k.get('firstName'), url=k.get('uri'), photo=k.get('thumbSrc'), name=k.get('name'), is_friend=k.get('is_friend'), gender=GENDERS.get(k.get('gender')))) return users @@ -791,7 +791,7 @@ class Client(object): if p['type'] == 'page': participants[p['fbid']] = Page(p['fbid'], url=p['href'], photo=p['image_src'], name=p['name']) elif p['type'] == 'user': - participants[p['fbid']] = User(p['fbid'], url=p['href'], first_name=p['short_name'], is_friend=p['is_friend'], gender=GENDERS[p['gender']], photo=p['image_src'], name=p['name']) + participants[p['fbid']] = User(p['fbid'], url=p['href'], first_name=p['short_name'], is_friend=p['is_friend'], gender=GENDERS.get(p['gender']), photo=p['image_src'], name=p['name']) else: raise FBchatException('A participant had an unknown type {}: {}'.format(p['type'], p)) diff --git a/fbchat/graphql.py b/fbchat/graphql.py index 7d91d95..8bc69bd 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -154,7 +154,7 @@ def graphql_to_user(user): first_name=user.get('first_name'), last_name=user.get('last_name'), is_friend=user.get('is_viewer_friend'), - gender=GENDERS[user.get('gender')], + gender=GENDERS.get(user.get('gender')), affinity=user.get('affinity'), nickname=c_info.get('nickname'), color=c_info.get('color'), diff --git a/fbchat/utils.py b/fbchat/utils.py index ec57691..f9670fc 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -74,13 +74,12 @@ GENDERS = { #'': 'female_singular_guess', #'': 'male_singular_guess', #'': 'mixed', - #'': 'neuter_singular', + 'NEUTER': 'neuter_singular', #'': 'unknown_singular', #'': 'female_plural', #'': 'male_plural', #'': 'neuter_plural', #'': 'unknown_plural', - None: None } class ReqUrl(object):