This commit is contained in:
+24
-7
@@ -1,5 +1,6 @@
|
||||
const fetch = require("node-fetch");
|
||||
const moment = require("moment-timezone")
|
||||
const puppeteer = require('puppeteer');
|
||||
const fs = require("fs")
|
||||
var html_to_pdf = require('html-pdf-node');
|
||||
let settings = {
|
||||
@@ -9,7 +10,7 @@ let days = "2"
|
||||
//var today = new Date();
|
||||
//var date = (today.getMonth() + 1) + '/' + today.getDate() + '/' + today.getFullYear();
|
||||
var headerhtml = "<h1>Pass Predictions for Palmyra, ME</h1><h3>(44.8453175, -69.3449081)</h3><h5>Information provided by n2yo.com</h5><br>"
|
||||
var footerhtml = "<br><h5>©2022 Nicholas Pease<br>Generated on "+new Date()+"</h5>"
|
||||
var footerhtml = "<br><h5>©2022 Nicholas Pease<br>Generated on "+new Date()+"</h5>"
|
||||
// Use n2yo API and grab Satellite Data
|
||||
const getSatelliteInfo = async id => {
|
||||
try {
|
||||
@@ -38,9 +39,9 @@ function createSection(json) {
|
||||
json.passes.forEach(function (element, key) {
|
||||
json.passes[key]
|
||||
if (body) {
|
||||
body = body + "<tr><td style='text-align: center'>" + convertTimestamp(json.passes[key].startUTC) + "</td><td style='text-align: center'>" + json.passes[key].maxEl + "°</td><td style='text-align: center'>" + convertTimestamp(json.passes[key].endUTC) + "</td></tr>"
|
||||
body = body + "<tr><td style='text-align: center'>" + convertTimestamp(json.passes[key].startUTC) + "</td><td style='text-align: center'>" + json.passes[key].maxEl + "°</td><td style='text-align: center'>" + convertTimestamp(json.passes[key].endUTC) + "</td></tr>"
|
||||
} else {
|
||||
body = "<tr><td style='text-align: center'>" + convertTimestamp(json.passes[key].startUTC) + "</td><td style='text-align: center'>" + json.passes[key].maxEl + "°</td><td style='text-align: center'>" + convertTimestamp(json.passes[key].endUTC) + "</td></tr>"
|
||||
body = "<tr><td style='text-align: center'>" + convertTimestamp(json.passes[key].startUTC) + "</td><td style='text-align: center'>" + json.passes[key].maxEl + "°</td><td style='text-align: center'>" + convertTimestamp(json.passes[key].endUTC) + "</td></tr>"
|
||||
}
|
||||
})
|
||||
var html = headerinfo + header + body + end
|
||||
@@ -80,8 +81,24 @@ function createSection(json) {
|
||||
content: messagehtml
|
||||
};
|
||||
fs.writeFileSync("/var/www/html/reports/satellitepasspredictions.html", messagehtml)
|
||||
html_to_pdf.generatePdf(file, options).then(pdfBuffer => {
|
||||
fs.writeFileSync("/var/www/html/reports/satellitepasspredictions.pdf", pdfBuffer)
|
||||
});
|
||||
savetoPDF()
|
||||
|
||||
})();
|
||||
|
||||
})();
|
||||
|
||||
async function savetoPDF() {
|
||||
var margins = {
|
||||
top: "42",
|
||||
bottom: "46",
|
||||
left: "10"
|
||||
}
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
await page.goto('https://server1.nicholaspease.com/reports/satellitepasspredictions.html');
|
||||
await page.pdf({
|
||||
path: '/var/www/html/reports/satellitepasspredictions.pdf',
|
||||
printBackground: true,
|
||||
margin: margins
|
||||
});
|
||||
await browser.close();
|
||||
}
|
||||
Reference in New Issue
Block a user