Skip to content

Commit

Permalink
Warn about outposts in combination with Froide
Browse files Browse the repository at this point in the history
  • Loading branch information
quinn-dev committed Jul 13, 2021
1 parent e3eac11 commit b9ab780
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ You can then use the `-u` option to pass in the URL:
$ schulfinder schools.json -u https://schulfinder.kultus-bw.de/?q=P3Rlcm09aHR0cHM6Ly9iaXQubHkvM3I0OUJySSZkaXN0YW5jZT0mb3duZXI9Jm91dHBvc3RzPTEm
```

**Note:** Make sure to exclude outposts by switching off `Außenstellen berücksichtigen` (within `Erweitert` settings) when using the `-u` option in combination with `-f`, since outposts often lack important data fields (like email, phone number and fax).

### FragDenStaat

`schulfinder` supports the data format used by [Froide](https://github.com/okfde/froide) to import public bodies (see the [format documentation](https://froide.readthedocs.io/en/latest/importpublicbodies/#format)). Froide is the Freedom of Information Portal used by the German project [FragDenStaat](https://fragdenstaat.de/) and its [Austrian counterpart](https://fragdenstaat.at/).
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"dependencies": {
"chalk": "^4.1.1",
"enquirer": "^2.3.6",
"got": "^11.8.2",
"libphonenumber-js": "^1.9.21",
"meow": "^10.0.1",
Expand Down
34 changes: 27 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import {
nullable
} from 'superstruct'
import ora from 'ora'
import enquirer from 'enquirer'
import pMap from 'p-map'
import {District, SimpleSchool, DetailedSchool} from './types.js'
import { quitWithError } from './cli.js'
import { quit, quitWithError } from './cli.js'
import { format } from 'libphonenumber-js'

const baseURL = 'https://schulfinder.kultus-bw.de/api/'

Expand Down Expand Up @@ -98,17 +100,13 @@ export const getSchools = async (parameters: string | Record<string, string | nu
})
}

export const getSchoolsByURL = async (url: string, quiet = false) => {
const spinner = ora('Loading school list')
export const getSchoolsByURL = async (url: string, froide = false, quiet = false) => {
const spinner = ora()

if (!(new URL(url).hostname == 'schulfinder.kultus-bw.de')) {
quitWithError(`Invalid URL: ${url}`)
}

if (!quiet) {
spinner.start()
}

url = url.trim()

const base64String = new URL(url).searchParams.get('q')
Expand All @@ -118,6 +116,28 @@ export const getSchoolsByURL = async (url: string, quiet = false) => {
} else {
const queryString = Buffer.from(base64String, 'base64').toString('utf-8')

if (froide) {
if (new URLSearchParams(queryString).get('outposts') == '1') {
spinner.warn('You have included outposts in your query. Importing outposts into Froide is highly discouraged.')

const answer = await enquirer.prompt({
type: 'confirm',
name: 'continue',
message: 'Do you want to continue?',
format: value => !!value ? 'yes' : 'no'
}) as {continue: boolean}

if (!answer.continue) {
spinner.fail('Aborted')
quit(1)
}
}
}

if (!quiet) {
spinner.start('Loading school list')
}

const schools = await getSchools(queryString)

if (!quiet) {
Expand Down
4 changes: 3 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from './api.js'
import {formatToFroide} from './formats.js'

export const quit = (statusCode: number) => process.exit(statusCode)

const {unparse} = papaparse

const cli = meow(`
Expand Down Expand Up @@ -76,7 +78,7 @@ export const quitWithError = (message: string) => {
let schoolsWithoutDetails

if (options.url) {
schoolsWithoutDetails = await getSchoolsByURL(options.url, options.quiet)
schoolsWithoutDetails = await getSchoolsByURL(options.url, options.froide, options.quiet)
} else {
const districts = await getDistricts(options.quiet)
schoolsWithoutDetails = await getSchoolsByDistricts(districts, options.quiet)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ enhanced-resolve@^0.9.1:
memory-fs "^0.2.0"
tapable "^0.1.8"

enquirer@^2.3.5:
enquirer@^2.3.5, enquirer@^2.3.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d"
integrity sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==
Expand Down

0 comments on commit b9ab780

Please sign in to comment.