added an hour delay
This commit is contained in:
parent
057853d1c5
commit
15d5275a87
58
src/index.js
58
src/index.js
|
@ -73,8 +73,6 @@ app.get('/callback', function(req, res) {
|
||||||
access_token = credentials.token;
|
access_token = credentials.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lap = 0;
|
|
||||||
|
|
||||||
let static_image_url = "https://weather.bangkok.go.th/Images/Radar/radarh.jpg";
|
let static_image_url = "https://weather.bangkok.go.th/Images/Radar/radarh.jpg";
|
||||||
let animated_image_url = "https://dds.bangkok.go.th/Radar/radar_rain.gif";
|
let animated_image_url = "https://dds.bangkok.go.th/Radar/radar_rain.gif";
|
||||||
|
|
||||||
|
@ -86,9 +84,8 @@ app.get('/callback', function(req, res) {
|
||||||
await Fetch.save_image(static_image_url, static_radar_path);
|
await Fetch.save_image(static_image_url, static_radar_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let post_lap = 0;
|
||||||
async function post() {
|
async function post() {
|
||||||
lap += 1;
|
|
||||||
console.log(lap);
|
|
||||||
let raw_date = new Date();
|
let raw_date = new Date();
|
||||||
|
|
||||||
let curr_static_image_size = fs.statSync(static_radar_path).size;
|
let curr_static_image_size = fs.statSync(static_radar_path).size;
|
||||||
|
@ -98,34 +95,43 @@ app.get('/callback', function(req, res) {
|
||||||
console.log("Scanned size: " + fetch_static_image_size);
|
console.log("Scanned size: " + fetch_static_image_size);
|
||||||
|
|
||||||
if(fetch_static_image_size != curr_static_image_size) {
|
if(fetch_static_image_size != curr_static_image_size) {
|
||||||
console.log("File size change detected!");
|
if(post_lap == 0 || post_lap == 12) { // 12 * 5 = 60
|
||||||
await Fetch.save_image(static_image_url, static_radar_path);
|
console.log("File size change detected!");
|
||||||
await Fetch.save_image(animated_image_url, animated_radar_path);
|
await Fetch.save_image(static_image_url, static_radar_path);
|
||||||
|
await Fetch.save_image(animated_image_url, animated_radar_path);
|
||||||
|
|
||||||
// Fetch static image
|
// Fetch static image
|
||||||
let static_radar_image_name = `${raw_date.toISOString()}.jpg`;
|
let static_radar_image_name = `${raw_date.toISOString()}.jpg`;
|
||||||
const upload_static_radar = await Post.create_image(host, access_token, static_radar_image_name, static_radar_path);
|
const upload_static_radar = await Post.create_image(host, access_token, static_radar_image_name, static_radar_path);
|
||||||
|
|
||||||
// Fetch animated image
|
// Fetch animated image
|
||||||
let animated_radar_image_name = `${raw_date.toISOString()}.gif`;
|
let animated_radar_image_name = `${raw_date.toISOString()}.gif`;
|
||||||
const upload_gif_radar = await Post.create_image(host, access_token, animated_radar_image_name, animated_radar_path);
|
const upload_gif_radar = await Post.create_image(host, access_token, animated_radar_image_name, animated_radar_path);
|
||||||
|
|
||||||
let radar_caption = await Fetch.get_radar_caption();
|
let radar_caption = await Fetch.get_radar_caption();
|
||||||
let note_caption = `$[x2 Bangkok Raindar Update]\n**${raw_date.toLocaleString('th-TH')}**\n\n${radar_caption}\n\nLeft: Current Observation\nRight: 3 hour forecast\n\n#bangkok #weather #bangkokweather`
|
let note_caption = `$[x2 Bangkok Raindar Update]\n**${raw_date.toLocaleString('th-TH')}**\n\n${radar_caption}\n\nLeft: Current Observation\nRight: 3 hour forecast\n\n#bangkok #weather #bangkokweather`
|
||||||
const post_note = await Post.create_note(
|
const post_note = await Post.create_note(
|
||||||
host,
|
host,
|
||||||
access_token,
|
access_token,
|
||||||
note_caption,
|
note_caption,
|
||||||
[upload_static_radar.id, upload_gif_radar.id],
|
[upload_static_radar.id, upload_gif_radar.id],
|
||||||
"public"
|
"public"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(post_note.createdNote) {
|
if(post_note.createdNote) {
|
||||||
console.log("Note created!");
|
console.log("Note created!");
|
||||||
|
post_lap++;
|
||||||
|
|
||||||
|
if(post_lap == 12) {
|
||||||
|
post_lap = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("Note was not created");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Note was not created");
|
console.log("Skipping post");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("No change in data, go on.");
|
console.log("No change in data, go on.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue