Skip to content

Commit

Permalink
Migrate lamadava from gql to v2 API
Browse files Browse the repository at this point in the history
The GQL API is temporarily unavailable.
  • Loading branch information
mariocj89 committed Jun 4, 2024
1 parent eee9ded commit 03d9873
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions eas/api/instagram/lamadava.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

LAMADAVA_APIK = settings.LAMADAVA_APIK
LOG = logging.getLogger(__name__)
MAX_PAGE_LAMADAVA = 50
ONE_MINUTE = 60 # seconds


Expand All @@ -28,18 +27,21 @@ def _session(): # pragma: no cover
def fetch_comments(media_pk): # pragma: no cover
LOG.info("Sending request to lamadava for %s", media_pk)
response = _session().get(
"https://api.lamadava.com/gql/comments",
"https://api.lamadava.com/v2/media/comments",
params={
"media_id": media_pk,
"amount": MAX_PAGE_LAMADAVA,
"id": media_pk,
"access_key": LAMADAVA_APIK,
},
timeout=ONE_MINUTE * 2,
)
if not response.ok:
LOG.warning("Failed lamadava request! %s", response.text)
with contextlib.suppress(Exception):
if response.json()["exc_type"] == "NotFoundError":
if response.json()["exc_type"] in ("NotFoundError", "MediaUnavailable"):
return []
response.raise_for_status()
return response.json()
try:
return response.json()["response"]["comments"]
except KeyError:
LOG.warning("Failed lamadava request! %s", response.text)
raise

0 comments on commit 03d9873

Please sign in to comment.