-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetch.ts
More file actions
35 lines (33 loc) · 886 Bytes
/
fetch.ts
File metadata and controls
35 lines (33 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { fromEnv } from '@nordicsemiconductor/from-env'
import { promises as fs } from 'fs'
import { mkdir } from 'fs/promises'
import path from 'path'
import { getStravaData } from './getStravaData.js'
import { weekFolderName } from './lib/weekFolderName'
const { clientId, clientSecret, refreshToken } = fromEnv({
clientId: 'CLIENT_ID',
clientSecret: 'CLIENT_SECRET',
refreshToken: 'REFRESH_TOKEN',
})(process.env)
getStravaData({
clientId,
clientSecret,
refreshToken,
})
.then(async (data) => {
const stravaDir = path.join(process.cwd(), 'data', weekFolderName())
try {
await mkdir(stravaDir)
} catch {
// directory exists
}
await fs.writeFile(
path.join(stravaDir, `data-${new Date().toISOString()}.json`),
JSON.stringify(data, null, 2),
'utf-8',
)
})
.catch((error) => {
console.error('Failed to write to shadow')
console.error(error)
})