Skip to content

Commit

Permalink
develop parser chilton
Browse files Browse the repository at this point in the history
  • Loading branch information
nthu31 committed Jul 15, 2024
1 parent 215ef0b commit 095b755
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
14 changes: 14 additions & 0 deletions chilton/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"longname": "Chilton",
"name": "chilton",
"describe": "Recognizes the accesses to the platform Chilton",
"contact": "Violita Kovchegov",
"pkb": false,
"docurl": "http://analyses.ezpaarse.org/platforms/6688515723b4aef40b1b8fb3",
"domains": [
"app.chiltonlibrary.com",
"appcontent.chiltonlibrary.com"
],
"version": "2024-07-15",
"status": "beta"
}
53 changes: 53 additions & 0 deletions chilton/parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

'use strict';
const Parser = require('../.lib/parser.js');

/**
* Recognizes the accesses to the platform Chilton
* @param {Object} parsedUrl an object representing the URL to analyze
* main attributes: pathname, query, hostname
* @param {Object} ec an object representing the EC whose URL is being analyzed
* @return {Object} the result
*/
module.exports = new Parser(function analyseEC(parsedUrl, ec) {
let result = {};
let path = parsedUrl.pathname;
// uncomment this line if you need parameters
// let param = parsedUrl.query || {};

// use console.error for debuging
// console.error(parsedUrl);

let match;

if (/^\/search\/[a-zA-Z0-9]+$/i.test(path)) {
// https://app.chiltonlibrary.com/search/bulletins
// https://app.chiltonlibrary.com/search/repair
result.rtype = 'SEARCH';
result.mime = 'HTML';

} else if ((match = /^\/TSBs\/GM\/([0-9]+)\.pdf$/i.exec(path)) !== null) {
// https://appcontent.chiltonlibrary.com/TSBs/GM/6523447.pdf
// https://appcontent.chiltonlibrary.com/TSBs/GM/6520490.pdf
result.rtype = 'REPORT';
result.mime = 'PDF';
result.unitid = match[1];
} else if ((match = /^\/Videos_Animations\/VideoLibrary\/([0-9]+)\/([a-zA-Z0-9\s%]+)\.mp4$/i.exec(path)) !== null) {
// https://appcontent.chiltonlibrary.com/Videos_Animations/VideoLibrary/05/Installation of the brakes.mp4
// https://appcontent.chiltonlibrary.com/Videos_Animations/VideoLibrary/09/Sensor inputs help the PCM establish the engine operating conditions.mp4
result.rtype = 'VIDEO';
result.mime = 'MISC';
let decoded_title = decodeURI(match[2]);
result.title_id = decoded_title;
result.unitid = `${match[1]}/${decoded_title}`;
} else if ((match = /^\/testprepquiz\/([a-zA-Z0-9]+)$/i.exec(path)) !== null) {
// https://app.chiltonlibrary.com/testprepquiz/a1
// https://app.chiltonlibrary.com/testprepquiz/a10
result.rtype = 'EXERCISE';
result.mime = 'HTML';
result.unitid = match[1];
}

return result;
});
9 changes: 9 additions & 0 deletions chilton/test/chilton.2024-07-15.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
out-title_id;out-unitid;out-rtype;out-mime;in-url
;;SEARCH;HTML;https://app.chiltonlibrary.com/search/repair
;6523447;REPORT;PDF;https://appcontent.chiltonlibrary.com/TSBs/GM/6523447.pdf
;6520490;REPORT;PDF;https://appcontent.chiltonlibrary.com/TSBs/GM/6520490.pdf
Installation of the brakes;05/Installation of the brakes;VIDEO;MISC;https://appcontent.chiltonlibrary.com/Videos_Animations/VideoLibrary/05/Installation of the brakes.mp4
Sensor inputs help the PCM establish the engine operating conditions;09/Sensor inputs help the PCM establish the engine operating conditions;VIDEO;MISC;https://appcontent.chiltonlibrary.com/Videos_Animations/VideoLibrary/09/Sensor inputs help the PCM establish the engine operating conditions.mp4
;a1;EXERCISE;HTML;https://app.chiltonlibrary.com/testprepquiz/a1
;a10;EXERCISE;HTML;https://app.chiltonlibrary.com/testprepquiz/a10
;;SEARCH;HTML;https://app.chiltonlibrary.com/search/bulletins

0 comments on commit 095b755

Please sign in to comment.