[instagram] cache '/users/web_profile_info' results on disk (#8978)

In the rare case this endpoint returns results and not a 429 error,
store them locally so they can be re-used the next time this user
is downloaded from.
This commit is contained in:
Mike Fährmann
2026-02-05 11:09:02 +01:00
parent df8aaa7e22
commit 2ac55f4870

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2018-2020 Leonardo Taccari # Copyright 2018-2020 Leonardo Taccari
# Copyright 2018-2025 Mike Fährmann # Copyright 2018-2026 Mike Fährmann
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
@@ -11,7 +11,7 @@
from .common import Extractor, Message, Dispatch from .common import Extractor, Message, Dispatch
from .. import text, util, exception from .. import text, util, exception
from ..cache import cache, memcache from ..cache import cache
import itertools import itertools
import binascii import binascii
@@ -869,7 +869,7 @@ class InstagramRestAPI():
} }
return self._pagination_sections(endpoint, data) return self._pagination_sections(endpoint, data)
@memcache(keyarg=1) @cache(maxage=36500*86400, keyarg=1)
def user_by_name(self, screen_name): def user_by_name(self, screen_name):
endpoint = "/v1/users/web_profile_info/" endpoint = "/v1/users/web_profile_info/"
params = {"username": screen_name} params = {"username": screen_name}
@@ -879,7 +879,7 @@ class InstagramRestAPI():
except KeyError: except KeyError:
raise exception.NotFoundError("user") raise exception.NotFoundError("user")
@memcache(keyarg=1) @cache(maxage=36500*86400, keyarg=1)
def user_by_id(self, user_id): def user_by_id(self, user_id):
endpoint = f"/v1/users/{user_id}/info/" endpoint = f"/v1/users/{user_id}/info/"
return self._call(endpoint)["user"] return self._call(endpoint)["user"]
@@ -892,6 +892,7 @@ class InstagramRestAPI():
user = self.user_by_name(screen_name) user = self.user_by_name(screen_name)
if user is None: if user is None:
self.user_by_name.invalidate(screen_name)
raise exception.AuthorizationError( raise exception.AuthorizationError(
"Login required to access this profile") "Login required to access this profile")
if check_private and user["is_private"] and \ if check_private and user["is_private"] and \