Created
April 8, 2018 19:33
-
-
Save kettuniko/8718825cfe94d601faf69c38cea43cf9 to your computer and use it in GitHub Desktop.
Helsinki city-bike distance calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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