From 52e92c30f07d6714a8aa888e340988f0609d1805 Mon Sep 17 00:00:00 2001 From: Rafael Franco Date: Thu, 11 May 2023 18:17:36 -0300 Subject: [PATCH] feat: add workflow to study for me --- .github/workflows/streak-keeper.yml | 18 ++++++++++++++++++ index.js | 29 +++++++++++------------------ package.json | 1 + 3 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/streak-keeper.yml diff --git a/.github/workflows/streak-keeper.yml b/.github/workflows/streak-keeper.yml new file mode 100644 index 0000000..fdf2fb9 --- /dev/null +++ b/.github/workflows/streak-keeper.yml @@ -0,0 +1,18 @@ +name: Keep my Duolingo streak + +on: + push: + branches: + - main +# schedule: +# - cron: '0 9 * * *' + +env: + DUOLINGO_USER_ID: '123' + DUOLINGO_JWT: 'abc' + +jobs: + study: + runs-on: ubuntu-latest + steps: + - uses: ./ diff --git a/index.js b/index.js index a1689d4..a50e820 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,14 @@ -const id = document.cookie - .split(';') - .find(cookie => cookie.includes('logged_out_uuid')) - .split('=')[1] +const headers = { + 'Content-Type': 'application/json', + Authorization: `Bearer ${process.env.DUOLINGO_JWT}`, + 'user-agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', +} const { fromLanguage, learningLanguage, xpGains } = await fetch( - `https://www.duolingo.com/2017-06-30/users/${id}?fields=fromLanguage,learningLanguage,xpGains`, + `https://www.duolingo.com/2017-06-30/users/${process.env.DUOLINGO_USER_ID}?fields=fromLanguage,learningLanguage,xpGains`, { - credentials: 'include', - headers: { - 'Content-Type': 'application/json', - }, + headers, }, ).then(response => response.json()) @@ -65,10 +64,7 @@ const session = await fetch('https://www.duolingo.com/2017-06-30/sessions', { smartTipsVersion: 2, type: 'SPEAKING_PRACTICE', }), - credentials: 'include', - headers: { - 'Content-Type': 'application/json', - }, + headers, method: 'POST', }).then(response => response.json()) @@ -85,12 +81,9 @@ const response = await fetch( maxInLessonStreak: 9, shouldLearnThings: true, }), - credentials: 'include', - headers: { - 'Content-Type': 'application/json', - }, + headers, method: 'PUT', }, ).then(response => response.json()) -response.xpGain +console.log(response.xpGain) diff --git a/package.json b/package.json index 681ca57..bb0c78e 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "description": "Script to farm Duolingo XP", "main": "index.js", + "type": "module", "scripts": { "build": "esbuild index.js --platform=browser --outdir=dist --minify" },