-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetStravaData.ts
58 lines (53 loc) · 1.34 KB
/
getStravaData.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { teamList } from './config.js'
import { getStartTimeStamp } from './getStartTimeStamp'
import { getAccessToken } from './lib/api/getAccessToken.js'
import { getInfoFromApi } from './lib/getInfoFromApi.js'
import {
ClubData,
summarizeStravaData,
Summary,
} from './lib/summarizeStravaData.js'
export type ClubInfo = {
name: string
distance: number
hours: number
clubPoints: number
elevation: number
}
export const getStravaData = async ({
clientId,
clientSecret,
refreshToken,
}: {
clientId: string
clientSecret: string
refreshToken: string
}): Promise<Summary> => {
const startTimeStamp = await getStartTimeStamp({
dataFolder: './data',
})
console.log(
`Timestamp used for fetching`,
startTimeStamp,
new Date(startTimeStamp * 1000),
)
const clubData: ClubData = []
const accessToken = await getAccessToken({
clientId,
clientSecret,
refreshToken,
})
for (const team of teamList) {
const clubInfo = await getInfoFromApi(
`https://www.strava.com/api/v3/clubs/${team}?access_token=${accessToken}`,
)
const clubActivities = await getInfoFromApi(
`https://www.strava.com/api/v3/clubs/${team}/activities?access_token=${accessToken}&per_page=200&after=${startTimeStamp}`,
)
clubData.push({
activities: clubActivities.data as any,
info: clubInfo.data as any,
})
}
return summarizeStravaData(clubData)
}