diff --git a/satpredictionbot.js b/satpredictionbot.js
index 6b6b0ca..b0d49d1 100644
--- a/satpredictionbot.js
+++ b/satpredictionbot.js
@@ -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 = "
Pass Predictions for Palmyra, ME
(44.8453175, -69.3449081)
Information provided by n2yo.com
"
-var footerhtml = "
©2022 Nicholas Pease
Generated on "+new Date()+"
"
+var footerhtml = "
©2022 Nicholas Pease
Generated on "+new Date()+"
"
// 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 + "| " + convertTimestamp(json.passes[key].startUTC) + " | " + json.passes[key].maxEl + "° | " + convertTimestamp(json.passes[key].endUTC) + " |
"
+ body = body + "| " + convertTimestamp(json.passes[key].startUTC) + " | " + json.passes[key].maxEl + "° | " + convertTimestamp(json.passes[key].endUTC) + " |
"
} else {
- body = "| " + convertTimestamp(json.passes[key].startUTC) + " | " + json.passes[key].maxEl + "° | " + convertTimestamp(json.passes[key].endUTC) + " |
"
+ body = "| " + convertTimestamp(json.passes[key].startUTC) + " | " + json.passes[key].maxEl + "° | " + convertTimestamp(json.passes[key].endUTC) + " |
"
}
})
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()
-})();
\ No newline at end of file
+
+})();
+
+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();
+}
\ No newline at end of file