Last active
January 8, 2025 09:46
-
-
Save xentec/5a7392a0c5b744c81a28ffd269931359 to your computer and use it in GitHub Desktop.
CLI mensa plan for OTH Regensburg. Requires Nushell to run.
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
#!/usr/bin/env nu | |
def fetch [week: int] { | |
let url = $"https://www.stwno.de/infomax/daten-extern/csv/HS-R-tag/($week).csv" | |
( | |
http get --raw $url | |
| decode "iso-8859-1" | |
| str replace --regex "\n(\n|(;|\\())" "$2" # fix bullshit | |
| from csv -s ";" | |
) | |
} | |
# Show compact canteen food plan | |
def main [ | |
selection?: string, # Filter by food type (vegan, etc.) | |
--details, # Include allergene details | |
--week: int, # Specify specific week to display | |
] { | |
let now = (date now) | |
let w = if $week == null { $now | format date '%V' | str trim --left --char '0' | into int } else { $week } | |
( | |
fetch $w | |
| reject tag preis | |
| if $week == null { | |
where datum == ($now | format date "%d.%m.%Y") | |
| reject datum | |
} else { $in } | |
| if not $details { | |
update name {str replace --regex '([^\(]+)\(.+\)' '$1' | str trim} | |
} else { $in } | |
| if $selection != null { | |
update kennz {split row ','} | |
| filter {|r| $selection in $r.kennz } | |
| update kennz {str join ','} | |
} else { $in } | |
) | |
} | |
# Fetch all years worth of data as sanitized CSV | |
def "main all" [] { | |
let year_ago = (date now) - 52wk | |
( | |
1..=52 | |
| par-each {|w| fetch $w | upsert kw $w} | |
| flatten --all | |
| reject tag preis | |
| update datum {into datetime} | |
| where datum > $year_ago # fix leftover data | |
| move kw --after datum | |
| update stud {str replace ',' '.' | into float} | |
| update bed {str replace ',' '.' | into float} | |
| update gast {str replace ',' '.' | into float} | |
| rename --column {stud: preis-stud, bed: preis-bedienstet, gast: preis-gast} | |
| sort-by kw | |
| update datum {format date "%Y-%m-%d"} | |
| to csv | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expanded it a little bit into a function. Now you can filter by the 'kennz' row (if it is vegan, etc)