Skip to content

Commit

Permalink
feat: add workflow to study for me
Browse files Browse the repository at this point in the history
  • Loading branch information
rfoel committed May 11, 2023
1 parent 8423195 commit 52e92c3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/streak-keeper.yml
Original file line number Diff line number Diff line change
@@ -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: ./
29 changes: 11 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -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())

Expand Down Expand Up @@ -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())

Expand All @@ -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)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 52e92c3

Please sign in to comment.