From ce22222b9a063044cc5909aa408d728e3430cc08 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Mon, 14 Feb 2022 11:25:56 +0000 Subject: [PATCH] Fix errors found after running tests * Make passing "private" in when saving Twitter User data optional (because it's not in the downloaded archive of data) * Cope with the fact some idiot (me) decided to pass either a dict *or* a boolean from a method. For #229 --- ditto/twitter/fetch/savers.py | 4 +++- ditto/twitter/models.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ditto/twitter/fetch/savers.py b/ditto/twitter/fetch/savers.py index d18a19c3..51783a40 100644 --- a/ditto/twitter/fetch/savers.py +++ b/ditto/twitter/fetch/savers.py @@ -59,7 +59,6 @@ def save_user(self, user, fetch_time, download_avatar=True): "raw": raw_json, "screen_name": user["screen_name"], "name": user["name"], - "is_private": user["protected"], "is_verified": user["verified"], "profile_image_url_https": user["profile_image_url_https"], } @@ -67,6 +66,9 @@ def save_user(self, user, fetch_time, download_avatar=True): # When ingesting tweets there are lots of fields the 'user' element # doesn't have, compared to the API: + if "protected" in user: + defaults["is_private"] = user["protected"] + if "created_at" in user: defaults["created_at"] = self._api_time_to_datetime(user["created_at"]) diff --git a/ditto/twitter/models.py b/ditto/twitter/models.py index 6a8c96a9..8662c327 100644 --- a/ditto/twitter/models.py +++ b/ditto/twitter/models.py @@ -70,7 +70,11 @@ def save(self, *args, **kwargs): # It would be nice to make this more visible, but not sure how to # given we don't have access to a request at this point. - if "success" in result and result["success"] is False: + if ( + type(result) is dict + and "success" in result + and result["success"] is False + ): if "messages" in result: messages = ", ".join(result["messages"]) else: