From 20e89d157c16efb1692f4606cab1db1e382d2113 Mon Sep 17 00:00:00 2001 From: Rafael Franco Date: Mon, 15 May 2023 11:22:08 -0300 Subject: [PATCH] feat: add number of lessons input --- .github/workflows/study.yml | 11 ++- index.js | 144 ++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 72 deletions(-) diff --git a/.github/workflows/study.yml b/.github/workflows/study.yml index c5cf9c0..d51945d 100644 --- a/.github/workflows/study.yml +++ b/.github/workflows/study.yml @@ -1,6 +1,13 @@ name: Do a Duolingo lesson -on: [workflow_dispatch] +on: + workflow_dispatch: + inputs: + lessons: + default: 1 + description: 'Number of lessons to be done' + required: false + type: number env: DUOLINGO_JWT: ${{ secrets.DUOLINGO_JWT }} @@ -16,3 +23,5 @@ jobs: node-version: 18 - run: node index.js + env: + LESSONS: ${{ inputs.lessons }} diff --git a/index.js b/index.js index 35f0b39..5bdd9da 100644 --- a/index.js +++ b/index.js @@ -16,78 +16,80 @@ const { fromLanguage, learningLanguage, xpGains } = await fetch( }, ).then(response => response.json()) -const session = await fetch('https://www.duolingo.com/2017-06-30/sessions', { - body: JSON.stringify({ - challengeTypes: [ - 'assist', - 'characterIntro', - 'characterMatch', - 'characterPuzzle', - 'characterSelect', - 'characterTrace', - 'completeReverseTranslation', - 'definition', - 'dialogue', - 'form', - 'freeResponse', - 'gapFill', - 'judge', - 'listen', - 'listenComplete', - 'listenMatch', - 'match', - 'name', - 'listenComprehension', - 'listenIsolation', - 'listenTap', - 'partialListen', - 'partialReverseTranslate', - 'readComprehension', - 'select', - 'selectPronunciation', - 'selectTranscription', - 'syllableTap', - 'syllableListenTap', - 'speak', - 'tapCloze', - 'tapClozeTable', - 'tapComplete', - 'tapCompleteTable', - 'tapDescribe', - 'translate', - 'typeCloze', - 'typeClozeTable', - 'typeCompleteTable', - ], - fromLanguage, - isFinalLevel: false, - isV2: true, - juicy: true, - learningLanguage, - skillId: xpGains.find(xpGain => xpGain.skillId).skillId, - smartTipsVersion: 2, - type: 'SPEAKING_PRACTICE', - }), - headers, - method: 'POST', -}).then(response => response.json()) - -const response = await fetch( - `https://www.duolingo.com/2017-06-30/sessions/${session.id}`, - { +for (let i = 0; i < process.env.LESSONS; i++) { + const session = await fetch('https://www.duolingo.com/2017-06-30/sessions', { body: JSON.stringify({ - ...session, - heartsLeft: 0, - startTime: (+new Date() - 60000) / 1000, - enableBonusPoints: false, - endTime: +new Date() / 1000, - failed: false, - maxInLessonStreak: 9, - shouldLearnThings: true, + challengeTypes: [ + 'assist', + 'characterIntro', + 'characterMatch', + 'characterPuzzle', + 'characterSelect', + 'characterTrace', + 'completeReverseTranslation', + 'definition', + 'dialogue', + 'form', + 'freeResponse', + 'gapFill', + 'judge', + 'listen', + 'listenComplete', + 'listenMatch', + 'match', + 'name', + 'listenComprehension', + 'listenIsolation', + 'listenTap', + 'partialListen', + 'partialReverseTranslate', + 'readComprehension', + 'select', + 'selectPronunciation', + 'selectTranscription', + 'syllableTap', + 'syllableListenTap', + 'speak', + 'tapCloze', + 'tapClozeTable', + 'tapComplete', + 'tapCompleteTable', + 'tapDescribe', + 'translate', + 'typeCloze', + 'typeClozeTable', + 'typeCompleteTable', + ], + fromLanguage, + isFinalLevel: false, + isV2: true, + juicy: true, + learningLanguage, + skillId: xpGains.find(xpGain => xpGain.skillId).skillId, + smartTipsVersion: 2, + type: 'SPEAKING_PRACTICE', }), headers, - method: 'PUT', - }, -).then(response => response.json()) + method: 'POST', + }).then(response => response.json()) + + const response = await fetch( + `https://www.duolingo.com/2017-06-30/sessions/${session.id}`, + { + body: JSON.stringify({ + ...session, + heartsLeft: 0, + startTime: (+new Date() - 60000) / 1000, + enableBonusPoints: false, + endTime: +new Date() / 1000, + failed: false, + maxInLessonStreak: 9, + shouldLearnThings: true, + }), + headers, + method: 'PUT', + }, + ).then(response => response.json()) -console.log({ xp: response.xpGain }) + console.log({ xp: response.xpGain }) +}