Skip to content

Commit

Permalink
πŸ› Raise error if parsed station list is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jh0ker committed May 2, 2024
1 parent ccec18e commit 6aa48c3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scraper/src/loadStations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = async function loadStations (baseMinYear) {
const url =
'https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/daily/kl/recent/KL_Tageswerte_Beschreibung_Stationen.txt';
const raw = (await got(url, { encoding: 'latin1' })).body;
return parseFixedWidth(raw, {
const stations = parseFixedWidth(raw, {
// The format was changed sometime between 2024-04-15 and 2024-05-01
//skip: 3,
//widths: [5, 9, 9, 15, 12, 10, 42, 22],
Expand All @@ -40,6 +40,11 @@ module.exports = async function loadStations (baseMinYear) {
.filter(station => !STATION_BLACKLIST.includes(station.name))
.filter(d => dayjs(d.from).year() <= baseMinYear && dayjs().diff(d.to, 'day') < 5)
.sort((a, b) => (a.slug > b.slug ? 1 : b.slug > a.slug ? -1 : 0));

if (stations.length === 0) {
throw new Error('No stations found');
}
return stations;
};

function parseFixedWidth (data, { skip = 0, widths = [], names = [], trim = true }) {
Expand Down

0 comments on commit 6aa48c3

Please sign in to comment.