updated gif
This commit is contained in:
parent
f2a9404876
commit
e9a4bfe264
Binary file not shown.
After Width: | Height: | Size: 1.9 MiB |
Binary file not shown.
Before Width: | Height: | Size: 279 KiB After Width: | Height: | Size: 279 KiB |
35
src/index.js
35
src/index.js
|
@ -32,7 +32,7 @@ client.once(Events.ClientReady, readyClient => {
|
|||
|
||||
async function get_rain_image() {
|
||||
try {
|
||||
const radar_image = await axios.get('https://weather.bangkok.go.th/Images/Radar/radarh.jpg', {
|
||||
const radar_image = await axios.get('https://weather.bangkok.go.th/Images/Radar/radar.gif', {
|
||||
responseType: "stream"
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,7 @@ async function get_radar_caption() {
|
|||
return root.querySelector('#repeaDaily_lblDESCRIPTION_0').childNodes[0]._rawText;
|
||||
}
|
||||
|
||||
const curr_image_path = path.resolve("data", "current_radar.jpg");
|
||||
const curr_image_path = path.resolve("data", "current_radar.gif");
|
||||
|
||||
client.on('ready', () => {
|
||||
(async () => {
|
||||
|
@ -69,11 +69,20 @@ client.on('ready', () => {
|
|||
console.log("File Saved");
|
||||
|
||||
console.log("Updating on boot");
|
||||
|
||||
let date = new Date().toISOString().
|
||||
replace(/T/, ' '). // replace T with a space
|
||||
replace(/\..+/, '')
|
||||
|
||||
let caption = `# Weather Update\n## ${date}\n${radar_caption}`
|
||||
|
||||
let message = await channel.send({
|
||||
content: radar_caption,
|
||||
content: caption,
|
||||
files: [curr_image_path]
|
||||
});
|
||||
console.log(`Sent: ${message.content}`);
|
||||
|
||||
let message_id = message.id;
|
||||
console.log(`Sent ${message.id}: ${message.content}`);
|
||||
|
||||
setInterval(async () => {
|
||||
let curr_image_size = fs.statSync(curr_image_path).size;
|
||||
|
@ -88,16 +97,30 @@ client.on('ready', () => {
|
|||
console.log("File Saved");
|
||||
|
||||
let radar_image_size = radar_image[1];
|
||||
|
||||
console.log("Current: " + curr_image_size);
|
||||
console.log("New: " + radar_image_size);
|
||||
|
||||
if(radar_image_size != curr_image_size) {
|
||||
console.log("File change detected!");
|
||||
|
||||
await channel.messages.delete(message_id);
|
||||
console.log("Delete old message");
|
||||
|
||||
let date = new Date().toISOString().
|
||||
replace(/T/, ' '). // replace T with a space
|
||||
replace(/\..+/, '')
|
||||
|
||||
let caption = `# Weather Update\n## ${date} Asia/Bangkok\n${radar_caption}`
|
||||
|
||||
let message = await channel.send({
|
||||
content: radar_caption,
|
||||
content: caption,
|
||||
files: [curr_image_path]
|
||||
});
|
||||
console.log(`Sent: ${message.content}`);
|
||||
|
||||
console.log(`Sent ${message.id}: ${message.content}`);
|
||||
message_id = message.id;
|
||||
console.log(message_id);
|
||||
} else {
|
||||
console.log("No change in data, go on.");
|
||||
}
|
||||
|
|
28
test.js
28
test.js
|
@ -1,28 +0,0 @@
|
|||
import axios from "axios";
|
||||
import { parse } from 'node-html-parser';
|
||||
|
||||
axios.get('https://weather.bangkok.go.th/Radar/RadarHighResolution.aspx')
|
||||
.then(function(response) {
|
||||
// console.log(response);
|
||||
|
||||
const root = parse(response.data);
|
||||
|
||||
//console.log(root.firstChild.structure);
|
||||
// ul#list
|
||||
// li
|
||||
// #text
|
||||
|
||||
console.log(root.querySelector('#repeaDaily_lblDESCRIPTION_0').childNodes[0]._rawText);
|
||||
// { tagName: 'ul',
|
||||
// rawAttrs: 'id="list"',
|
||||
// childNodes:
|
||||
// [ { tagName: 'li',
|
||||
// rawAttrs: '',
|
||||
// childNodes: [Object],
|
||||
// classNames: [] } ],
|
||||
// id: 'list',
|
||||
// classNames: [] }
|
||||
//console.log(root.toString());
|
||||
})
|
||||
|
||||
//<span id="repeaDaily_lblDESCRIPTION_0">(.*?)<\/span>
|
Loading…
Reference in New Issue