Skip to content

Instantly share code, notes, and snippets.

@prhbrt
Last active October 23, 2024 19:23
Show Gist options
  • Save prhbrt/3388b570639e62058ab282ce6af9ab52 to your computer and use it in GitHub Desktop.
Save prhbrt/3388b570639e62058ab282ce6af9ab52 to your computer and use it in GitHub Desktop.
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
// 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