From ed364ee9a71f8ddc6eb15fea1e4dcb0867b15228 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sun, 16 Mar 2025 15:03:11 +0100 Subject: [PATCH] feat: Add pagination to WaniKani lessons fetcher for assignments --- personal_data/fetchers/wanikani_lessons.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/personal_data/fetchers/wanikani_lessons.py b/personal_data/fetchers/wanikani_lessons.py index 4c44115..fd11f79 100644 --- a/personal_data/fetchers/wanikani_lessons.py +++ b/personal_data/fetchers/wanikani_lessons.py @@ -26,10 +26,12 @@ class WaniKaniLessonsFetcher(Scraper): 'Authorization': f'Bearer {secrets.wanikani_api_key()}', 'Wanikani-Revision': '20170710', } - response = self.session.get(url, headers=headers) - response.raise_for_status() - data = response.json() - for assignment in data.get('data', []): - data = assignment['data'] - print(data) - yield data + while url: + response = self.session.get(url, headers=headers) + response.raise_for_status() + json_resp = response.json() + for assignment in json_resp.get('data', []): + data_item = assignment['data'] + print(data_item) + yield data_item + url = json_resp.get("pages", {}).get("next_url")