Closed turbobenny closed 4 years ago
Can you share with me your config.json file? or your codebase?
This could be a Windows-specific issue - the code that tries to find find the tempate directory is here: https://github.com/BlinkTagInc/gtfs-to-html/blob/master/lib/file-utils.js#L17
Hallo, thanks for your answer. I must add, that I am a total amateur. At the beginning I was unable to set a path for the config.json file. No path I set was accepted. It always said "can't find configuration file". In the end I solved it by looking into the package.json file where the program might look for it, The directory was System 32. I copied my config.json file into it and it worked. Finally I want to add, that I installed globally, so it is in &Appdata%. I set no custom template.
My config.json file { "mongoUrl": "mongodb://localhost:27017/gtfs", "agencies": [{ "agency_key": "VBB", "url": "https://transitfeeds.com/p/verkehrsverbund-berlin-brandenburg/213/latest/download" }], "beautify": false, "coordinatePrecision": 5, "dateFormat": "DD.MM.YYYY", "daysShortStrings": ["Mon", "Die", "Mit", "Don", "Fre", "Sam", "Son"], "daysStrings": ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Sonnabend", "Sonntag"], "defaultOrientation": "vertical", "effectiveDate": "02.06.2020", "interpolatedStopSymbol": "•", "interpolatedStopText": "Estimated time of arrival", "linkStopUrls": true, "mapboxAccessToken": "pk.eyXaX5F8oCJSYedim3yCnTGsVBfnRjsoXdy4Ej7ZZZydrCn2WMDXha5bPj5.bPj5xsBo8u8N8GJqJh", "menuType": "jump", "noDropoffSymbol": "null", "noDropoffText": "No drop off available", "noHead": false, "noPickupSymbol": "null", "noPickupText": "No pickup available", "noServiceSymbol": "null", "noServiceText": "No service at this stop", "outputFormat": "pdf", "requestDropoffSymbol": "null", "requestDropoffText": "Must request drop off", "requestPickupSymbol": "null", "requestPickupText": "Request stop - call for pickup", "serviceNotProvidedOnText": "Service not provided on", "serviceProvidedOnText": "Service provided on", "showArrivalOnDifference": null, "showMap": false, "showOnlyTimepoint": true, "showRouteTitle": true, "showStopCity": false, "showStopDescription": false, "skipImport": false, "sortingAlgorithm": "common", "templatePath": "views/timetable", "timeFormat": "hh:mma", "useParentStation": true, "verbose": true, "zipOutput": false }
The code: const path = require('path');
const archiver = require('archiver'); const beautify = require('js-beautify').html_beautify; const fs = require('fs-extra'); const pug = require('pug'); const puppeteer = require('puppeteer'); const sanitize = require('sanitize-filename'); const untildify = require('untildify');
const formatters = require('./formatters');
/*
config. */ function getTemplatePath(templateFileName, config) { let folderPath; if (config.templatePath === undefined) { folderPath = path.join(__dirname, '..', 'views/timetable/'); } else { folderPath = path.join(untildify(config.templatePath)); }
const filename = ${templateFileName}${(config.noHead === true) ? '' : '_full'}.pug
;
return path.join(folderPath, filename); }
/*
/*
Zips the content of the specified folder. */ exports.zipFolder = exportPath => { const output = fs.createWriteStream(path.join(exportPath, 'timetables.zip')); const archive = archiver('zip');
return new Promise((resolve, reject) => {
output.on('close', resolve);
archive.on('error', reject);
archive.pipe(output);
archive.glob(${exportPath}/**/*.{txt,css,html}
);
archive.finalize();
});
};
/*
Generate the filename for a given timetable. */ exports.generateFileName = (timetable, config) => { let filename = timetable.timetable_id;
for (const route of timetable.routes) {
if (route.route_short_name === '' || route.route_shortname === undefined) {
filename += `${route.route_longname.replace(/\s/g, '-')}; } else { filename +=
${route.route_short_name.replace(/\s/g, '-')}`;
}
}
if (timetable.direction_id !== '' && timetable.directionid !== undefined) { filename += `${timetable.direction_id}`; }
filename += _${formatters.formatDays(timetable, config).replace(/\s/g, '')}.html
;
return sanitize(filename).toLowerCase(); };
/*
Generates the folder name for a timetable page based on the date. */ exports.generateFolderName = timetablePage => { // Use first timetable in timetable page for start date and end date const timetable = timetablePage.consolidatedTimetables[0]; if (!timetable.start_date || !timetable.end_date) { return 'timetables'; }
return sanitize(${timetable.start_date}-${timetable.end_date}
);
};
/*
Render the HTML for a timetable based on the config. */ exports.renderFile = async (templateFileName, templateVars, config) => { const templatePath = getTemplatePath(templateFileName, config); let html = await pug.renderFile(templatePath, templateVars);
// Beautify HTML if setting is set if (config.beautify === true) { html = await beautify(html, { indent_size: 2 }); }
return html; };
/*
Render the PDF for a timetable based on the config.
*/
exports.renderPdf = async htmlPath => {
const pdfPath = htmlPath.replace(/html$/, 'pdf');
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.emulateMedia('screen');
await page.goto(file://${htmlPath}
, { waitUntil: 'networkidle0' });
await page.pdf({ path: pdfPath });
await browser.close(); };
Thank you. Regards
It's having trouble finding the path to the template directory.
Can you try removing the templatePath
config option entirely from your config.json file (to s
Or try putting the full path to the template directory in your config.json for templatePath
? Something like
C:\Users\Heinz-Jürgen Schücke\AppData\Roaming\npm\node_modules\gtfs-to-html\views\timetable
Hallo, sorry for the delay, but yesterday I didn't have the time to test what you proposed. Today I tested with "HTML". Removing the templatePath config option entirely from my config.json file worked. The program went through. The second, putting the full path to the template directory in my config.json did not work, but I'll try again. Tomorrow I'll try the same with "PDF" and I'll tell you the resullts. THank you very much again. The file I am working on is very big, and in fact I only need one agency. Do I have to delete the other agencies manually or is there a shorter way to get rid of thhem? Regards turbobenny
After a few weeks of trying to get gtfs-to-html work on a windows machine,I nearly succeeded. It works now until the point, where it should generate pdf timetables. There it stops not knowing which directory or file it should the timetables generate to. It refers to "views\timetable\timetablepage_full.pug", but I don't know what to do now. Do I have to create a directory or file now myself? And where? To what directory? Or do I need to make amendmends to an existing file? I don't understand what do do now. Ithink this is the last step, and I would so like gtfs-to-html to work for me. Thank you for your help. This is what it says:
VBB: Generating HTML timetables [-----------------------------------] 0/3273512 Error: Error: ENOENT: no such file or directory, open 'views\timetable\timetable page_full.pug' (node:864) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or dire ctory, open 'views\timetable\timetablepage_full.pug' at Object.openSync (fs.js:458:3) at Object.readFileSync (fs.js:360:35) at handleTemplateCache (C:\Users\Heinz-Jürgen Schücke\AppData\Roaming\npm\no de_modules\gtfs-to-html\node_modules\pug\lib\index.js:239:37) at Object.exports.renderFile (C:\Users\Heinz-Jürgen Schücke\AppData\Roaming\ npm\node_modules\gtfs-to-html\node_modules\pug\lib\index.js:452:10) at Object.exports.renderFile (C:\Users\Heinz-Jürgen Schücke\AppData\Roaming\ npm\node_modules\gtfs-to-html\lib\file-utils.js:99:24) at Object.exports.generateHTML (C:\Users\Heinz-Jürgen Schücke\AppData\Roamin g\npm\node_modules\gtfs-to-html\lib\utils.js:1153:32) at C:\Users\Heinz-Jürgen Schücke\AppData\Roaming\npm\node_modules\gtfs-to-ht ml\lib\gtfs-to-html.js:74:35 at async Promise.all (index 0) at async C:\Users\Heinz-Jürgen Schücke\AppData\Roaming\npm\node_modules\gtfs -to-html\bin\gtfs-to-html.js:68:5 (node:864) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This e rror originated either by throwing inside of an async function without a catch b lock, or by rejecting a promise which was not handled with .catch(). To terminat e the node process on unhandled promise rejection, use the CLI flag
--unhandled -rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejection s_mode). (rejection id: 2) (node:864) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprec ated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.