Skip to content

Commit

Permalink
Add additonal search paramter (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeil authored Jan 4, 2023
1 parent 54f5cba commit cb9d32c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Source: https://www.lanuv.nrw.de/luqs/messorte/messorte.php

Optionally accepts an `options` object as first parameter:

- `ort` search for a specifc city
- `kurzname` search for specific short name of stations
- `status: aktiv|inaktiv|alle` returns stations with the specified status
- `allStations: true` returns all active and inactive stations. Overrides the `status` option **Deprecated**

Expand Down
37 changes: 15 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const query = (url, options = {}) => {
request({
url,
method: options.method ? options.method : 'GET',
form: options.form ? options.form : undefined
formData: options.formData ? options.formData : undefined
}, function (error, response, body) {
if (error) {
reject(error)
Expand All @@ -41,37 +41,30 @@ const query = (url, options = {}) => {
/**
* Requests LUQS stations website and parse stations table.
*
* @param ort
* @param kurzname
* @param status
* @param options.allStations return all stations if true
* @returns Promise resolves with an array of all luqs stations
*/
const luqs = (options = {}) => {
return new Promise((resolve, reject) => {
let requestOptions
const { status, allStations } = options
if (status) {
requestOptions = {
method: 'POST',
form: {
auswahl_plz: 'alle',
auswahl_status: status,
auswahl_klassifizierung: 'alle'
}
}
}
const formData = {}
const { ort, kurzname, status, allStations } = options

if (ort) formData.suche_ort = ort
if (kurzname) formData.suche_kurzname = kurzname
if (status) formData.auswahl_status = status

if (allStations) {
console.info('Option allStations is deprecated and will be removed in a future release!')
requestOptions = {
method: 'POST',
form: {
auswahl_plz: 'alle',
auswahl_status: 'alle',
auswahl_klassifizierung: 'alle'
}
}
formData.auswahl_status = 'alle'
}

query(messorteUrl, requestOptions)
query(messorteUrl, {
method: 'POST',
formData: formData
})
.then($ => {
const stations = []
const tableRows = $('#wrapper > table > tbody > tr')
Expand Down

0 comments on commit cb9d32c

Please sign in to comment.