[twitter] slightly improve '_transform_user()'

This commit is contained in:
Mike Fährmann
2021-08-23 22:28:09 +02:00
parent c04f7ab139
commit 5919dc5b5a

View File

@@ -208,30 +208,32 @@ class TwitterExtractor(Extractor):
return tdata return tdata
def _transform_user(self, user): def _transform_user(self, user):
uid = user["id_str"] try:
cache = self._user_cache return self._user_cache[user["id_str"]]
except KeyError:
pass
if uid not in cache: uid = user["id_str"]
cache[uid] = { self._user_cache[uid] = udata = {
"id" : text.parse_int(uid), "id" : text.parse_int(uid),
"name" : user["screen_name"], "name" : user["screen_name"],
"nick" : user["name"], "nick" : user["name"],
"description" : user["description"], "description" : user["description"],
"location" : user["location"], "location" : user["location"],
"date" : text.parse_datetime( "date" : text.parse_datetime(
user["created_at"], "%a %b %d %H:%M:%S %z %Y"), user["created_at"], "%a %b %d %H:%M:%S %z %Y"),
"verified" : user.get("verified", False), "verified" : user.get("verified", False),
"profile_banner" : user.get("profile_banner_url", ""), "profile_banner" : user.get("profile_banner_url", ""),
"profile_image" : user.get( "profile_image" : user.get(
"profile_image_url_https", "").replace("_normal.", "."), "profile_image_url_https", "").replace("_normal.", "."),
"favourites_count": user["favourites_count"], "favourites_count": user["favourites_count"],
"followers_count" : user["followers_count"], "followers_count" : user["followers_count"],
"friends_count" : user["friends_count"], "friends_count" : user["friends_count"],
"listed_count" : user["listed_count"], "listed_count" : user["listed_count"],
"media_count" : user["media_count"], "media_count" : user["media_count"],
"statuses_count" : user["statuses_count"], "statuses_count" : user["statuses_count"],
} }
return cache[uid] return udata
def _users_result(self, users): def _users_result(self, users):
userfmt = self.config("users") userfmt = self.config("users")