Skip to content

Commit

Permalink
Fix errors found after running tests
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
philgyford committed Feb 14, 2022
1 parent dd90c1f commit ce22222
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ditto/twitter/fetch/savers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ 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"],
}

# 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"])

Expand Down
6 changes: 5 additions & 1 deletion ditto/twitter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ce22222

Please sign in to comment.