This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
forked from themaxsandelin/skolverket-api
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added data support for subjects in 'gymsar' level
- Loading branch information
1 parent
c22f27a
commit c7b5a2d
Showing
6 changed files
with
99 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Route manager for /gymsar/subjects | ||
// Data folder: gys | ||
|
||
// Dependencies | ||
const router = require('express').Router() | ||
const path = require('path') | ||
const fs = require('fs') | ||
const { parseString } = require('xml2js') | ||
|
||
// Helpers | ||
const formatter = require('../../helpers/gymsar/formatter') | ||
const latinize = require('../../helpers/latinize') | ||
|
||
const rootPath = path.resolve(__dirname + '/../../../files/gys') | ||
|
||
router.get('/', (req, res) => { | ||
const file = rootPath + '/subjectsAndCourses/amnen_och_kurser.xml' | ||
|
||
parseString(fs.readFileSync(file).toString(), (err, result) => { | ||
res.json(formatter.formatSubjects(result.SubjectsAndCourses.subject)) | ||
}) | ||
}) | ||
|
||
router.get('/:code', (req, res) => { | ||
const code = req.params.code.toLowerCase() | ||
const file = rootPath + '/subjectsAndCourses/amnen_och_kurser.xml' | ||
|
||
parseString(fs.readFileSync(file).toString(), (err, result) => { | ||
let validCode = false | ||
|
||
result.SubjectsAndCourses.subject.forEach(subject => { | ||
if (subject.code[0].toLowerCase() === code) { | ||
validCode = true | ||
|
||
let file = rootPath + '/subject/' + latinize(subject.name[0]) + '.xml' | ||
while (file.indexOf('–') > -1) { | ||
file = file.replace('–', '-') | ||
} | ||
|
||
parseString(fs.readFileSync(file), (err, result) => { | ||
res.json(formatter.formatSubjectData(result.subject)) | ||
}) | ||
} | ||
}) | ||
|
||
if (!validCode) res.status(404).send('Not found.') | ||
}) | ||
}) | ||
|
||
module.exports = router |
This file contains 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
This file contains 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