Skip to content

Instantly share code, notes, and snippets.

@kettuniko
Created April 8, 2018 19:33
Show Gist options
  • Save kettuniko/8718825cfe94d601faf69c38cea43cf9 to your computer and use it in GitHub Desktop.
Save kettuniko/8718825cfe94d601faf69c38cea43cf9 to your computer and use it in GitHub Desktop.
Helsinki city-bike distance calculator
// Calculates yearly distances you pedaled with Helsinki city bikes.
// Paste to browser console at https://kaupunkipyorat.hsl.fi/fi/activity
[...document.querySelectorAll('.activity-feed-item')].reduce((memo, current) => {
const departureText = current.querySelector('.departure-date').innerText
const [date] = departureText.split(' ')
const [,,year] = date.split('.')
const yearDistance = memo[year] || 0
const distanceText = current.querySelector('.covered-distance').innerText
const [distance] = distanceText.split('km')
const currentDistance = parseFloat(distance)
const yearDistanceWithCurrent = {[year]: yearDistance + currentDistance}
return {...memo, ...yearDistanceWithCurrent}
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment