问题描述
我的 Heroku 应用程序应该每天发送一次电子邮件,但每六个小时发送一次电子邮件。我已添加并配置 Heroku 调度程序,使其在 UTC 每天下午 2:00 运行,但出于某种原因,该应用程序继续每六小时运行一次。
这与“一次性 Dynos”有关吗?
web: node js/scraper.js
这是我的代码。
const realtor = require("realtorca");
const unirest = require("unirest");
const nodemailer = require("nodemailer");
const { staticMapUrl } = require("static-google-map");
//https://rapidapi.com/apidojo/api/realtor-canadian-real-estate?endpoint=apiendpoint_bc4d93dd-15c5-47de-b04e-854b2e6176be
var req = unirest(
"GET","https://realtor-canadian-real-estate.p.rapidapi.com/properties/list-residential"
);
req.query({
LongitudeMin: -79.44438,LongitudeMax: -79.404,LatitudeMin: 43.75135,LatitudeMax: 43.78448,PriceMax: 1500000,ZoomLevel: 15,BuildingTypeId: 1,//NOTE: if there are more than 50 records I need to figure out how to traverse through the pages
RecordsPerPage: 50,});
req.headers({
"x-rapidapi-key": "secret","x-rapidapi-host": "realtor-canadian-real-estate.p.rapidapi.com",useQueryString: true,});
let resultsArray = [];
req.end(function (res) {
if (res.error) throw new Error(res.error);
let totalResults = res.body.Paging.TotalRecords;
let mapObject = {};
let addMarkers = async function () {
for (i = 0; i < totalResults; i++) {
mapObject.markerGroups.push({
iconURL: `https%3A%2F%2Fapi.geoapify.com%2Fv1%2Ficon%2F%3Ftype%3Dmaterial%26color%3Dred%26icon%3Dcloud%26iconType%3Dawesome%26text%3D${i}%26apiKey%secret`,markers: [
{
location: {
lat: res.body.Pins[i].latitude,lng: res.body.Pins[i].longitude,},],});
}
};
mapObject = {
key: "secret",scale: 2,size: "1000x1000",format: "png",markerGroups: [],};
addMarkers();
let url = staticMapUrl(mapObject);
//LOGGING TO SEE WHAT HAPPENS
console.log(totalResults);
console.log(mapObject);
console.log(url);
const forLoop = async (_) => {
for (let i = 0; i < totalResults; i++) {
await resultsArray.push(
"<p>",res.body.Results[i].Property.Address.Addresstext + "<br />",res.body.Results[i].Property.Price + "<br />","Number of bathrooms: " +
res.body.Results[i].Building.BathroomTotal +
"<br />","Number of bedrooms: " +
res.body.Results[i].Building.bedrooms +
"<br />","http://www.realtor.ca" +
res.body.Results[i].RelativeDetailsURL +
"<br />","Notes: " + res.body.Results[i].PublicRemarks + "</p>"
);
}
console.log(resultsArray);
console.log(totalResults);
let transporter = nodemailer.createTransport({
host: "giow1039.siteground.us",port: 587,secure: false,// true for 465,false for other ports
auth: {
user: "notifications@danielpuiatti.com",pass: "secret",});
// send mail with defined transport object
let info = {
from: "notifications@danielpuiatti.com",// sender address
to: "dpuiatti@gmail.com",// list of receivers
subject: "Hello ✔",// Subject line
html:
"<h1>Your daily Realtor.ca update</h1>" +
String(resultsArray).replace(/,/g,"").replace(/\|/g," | ") +
'<img src="' +
url +
'" width="800" height="600"/>',};
transporter.sendMail(info,function (err,info) {
if (err) {
console.log(err);
return;
}
console.log(info.response);
});
};
forLoop();
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)