added an hour delay

This commit is contained in:
Win 2024-07-18 17:27:12 +07:00
parent 057853d1c5
commit 15d5275a87
1 changed files with 34 additions and 28 deletions

View File

@ -73,8 +73,6 @@ app.get('/callback', function(req, res) {
access_token = credentials.token;
}
let lap = 0;
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";
@ -86,9 +84,8 @@ app.get('/callback', function(req, res) {
await Fetch.save_image(static_image_url, static_radar_path);
}
let post_lap = 0;
async function post() {
lap += 1;
console.log(lap);
let raw_date = new Date();
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);
if(fetch_static_image_size != curr_static_image_size) {
console.log("File size change detected!");
await Fetch.save_image(static_image_url, static_radar_path);
await Fetch.save_image(animated_image_url, animated_radar_path);
if(post_lap == 0 || post_lap == 12) { // 12 * 5 = 60
console.log("File size change detected!");
await Fetch.save_image(static_image_url, static_radar_path);
await Fetch.save_image(animated_image_url, animated_radar_path);
// Fetch static image
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);
// Fetch static image
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);
// Fetch animated image
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);
// Fetch animated image
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);
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`
const post_note = await Post.create_note(
host,
access_token,
note_caption,
[upload_static_radar.id, upload_gif_radar.id],
"public"
)
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`
const post_note = await Post.create_note(
host,
access_token,
note_caption,
[upload_static_radar.id, upload_gif_radar.id],
"public"
)
if(post_note.createdNote) {
console.log("Note created!");
if(post_note.createdNote) {
console.log("Note created!");
post_lap++;
if(post_lap == 12) {
post_lap = 0;
}
} else {
console.log("Note was not created");
}
} else {
console.log("Note was not created");
console.log("Skipping post");
}
} else {
console.log("No change in data, go on.");
}