Last active
October 23, 2024 19:23
-
-
Save prhbrt/3388b570639e62058ab282ce6af9ab52 to your computer and use it in GitHub Desktop.
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
import re | |
import json | |
import pandas as pd | |
# Drop in the JSON of `allRows` | |
data = pd.DataFrame(json.loads(""" | |
<DATA> | |
"""), columns=['from', 'to', 'plate', 'duration']) | |
exp = re.compile( | |
'((?P<uur>[0-9]+) (?:uren|uur))?' | |
' ' | |
'?((?P<min>[0-9]+) (?:minuten|min))?' | |
) | |
data['year'] = data['from'].str[6:10] | |
duration = data['duration'].apply(lambda x: pd.Series(exp.match(x).groupdict())).astype(float).fillna(0).astype(int) | |
data['duration'] = duration['uur'] * 60 + duration['min'] | |
data.groupby(['year', 'plate'])['duration'].sum() / 60 |
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
// Drop at the history page of the parking admin of the municipality Groningen | |
var allRows=[]; | |
document.querySelectorAll('ol.pagination > li:nth-child(1) > a')[0].click(); | |
var nPages = parseInt( | |
document.querySelectorAll('ol.pagination > li:nth-child(3) > a')[0].textContent.split(' van ')[1] | |
) | |
for(var i=0; i<nPages; ++i) { | |
setTimeout(() => { | |
var rows = Array.from(document.querySelectorAll('table tr.ng-scope')).filter( | |
row => row.children.length == 3 | |
).map( | |
row => Array.from( | |
row.children[0].children | |
).concat( | |
Array.from(row.children).slice(1) | |
) | |
).map(row => row.map(cell => cell.textContent)) | |
allRows = allRows.concat(rows) | |
document.querySelectorAll('ol.pagination > li:nth-child(4) > a')[0].click(); | |
}, 1000 * (i+1) ) | |
} | |
setTimeout(() => console.log(JSON.stringify(allRows)), nPages+2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment