confusion
This commit is contained in:
parent
131cb57e13
commit
c420610541
|
@ -0,0 +1,27 @@
|
||||||
|
async function get_radar_image() {
|
||||||
|
try {
|
||||||
|
let radar_src = "https://weather.bangkok.go.th/Images/Radar/radarh.jpg"
|
||||||
|
const radar_image = await axios.get(radar_src, {
|
||||||
|
responseType: "stream"
|
||||||
|
});
|
||||||
|
|
||||||
|
const radar_image_size = radar_image.headers['content-length'];
|
||||||
|
console.log("Got Radar Data");
|
||||||
|
return [radar_image, radar_image_size];
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return [error];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function get_radar_caption() {
|
||||||
|
const response = await axios.get('https://weather.bangkok.go.th/Radar/RadarHighResolution.aspx');
|
||||||
|
|
||||||
|
let root = parse(response.data);
|
||||||
|
console.log("Got Radar Caption")
|
||||||
|
return root.querySelector('#repeaDaily_lblDESCRIPTION_0').childNodes[0]._rawText;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.get_radar_image = get_radar_image;
|
||||||
|
module.exports.get_radar_caption = get_radar_caption;
|
|
@ -11,13 +11,11 @@ async function create_image(host, access_token, file_path) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(create.status == 200)
|
|
||||||
|
|
||||||
return create;
|
return create;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function create_note(host, access_token, text, media_ids, visibility) {
|
async function create_note(host, access_token, text, media_ids, visibility) {
|
||||||
axios.post(`${host}/api/notes/create`, {
|
const create = axios.post(`${host}/api/notes/create`, {
|
||||||
text: text,
|
text: text,
|
||||||
mediaIds: media_ids,
|
mediaIds: media_ids,
|
||||||
visibility: visibility
|
visibility: visibility
|
||||||
|
@ -25,11 +23,9 @@ async function create_note(host, access_token, text, media_ids, visibility) {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${access_token}`
|
'Authorization': `Bearer ${access_token}`
|
||||||
}
|
}
|
||||||
}).then((response) => {
|
|
||||||
let data = response.data;
|
|
||||||
|
|
||||||
return data;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return create;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.create_image = create_image;
|
module.exports.create_image = create_image;
|
||||||
|
|
38
src/index.js
38
src/index.js
|
@ -2,6 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
import { pipeline } from 'node:stream/promises';
|
||||||
|
|
||||||
import * as Post from './api/post.cjs';
|
import * as Post from './api/post.cjs';
|
||||||
import * as Auth from './api/auth.cjs';
|
import * as Auth from './api/auth.cjs';
|
||||||
|
@ -51,19 +52,32 @@ app.get('/callback', function(req, res) {
|
||||||
access_token = token_file.token;
|
access_token = token_file.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
let static_radar_path = path.join(__dirname, '/data/current_radar.jpg');
|
/* setInterval(async function post() {
|
||||||
const static_radar_image = await Post.create_image(host, access_token, static_radar_path);
|
let static_radar_path = path.join(__dirname, '/data/current_radar.jpg');
|
||||||
const static_radar_image__id = static_radar_image.id;
|
const static_radar_image = await Post.create_image(host, access_token, static_radar_path);
|
||||||
console.log(static_radar_image);
|
const static_radar_image__id = static_radar_image.data.id;
|
||||||
|
console.log(static_radar_image__id);
|
||||||
|
|
||||||
/* let note_text = "hello fediverse";
|
return ;
|
||||||
const post_note = await Post.create_note(
|
}, 60000); */
|
||||||
host,
|
|
||||||
access_token,
|
/* setInterval(async () => {
|
||||||
note_text,
|
let date = new Date().toLocaleString('th-TH');
|
||||||
["" + static_radar_image__id],
|
/* let curr_image_path = path.join(__dirname, '/data/' + date + '.jpg');
|
||||||
"public"
|
|
||||||
) */
|
let static_radar_path = path.join(__dirname, '/data/current_radar.jpg');
|
||||||
|
const static_radar_image = Post.create_image(host, access_token, name, static_radar_path);
|
||||||
|
const static_radar_image__id = static_radar_image.data.id;
|
||||||
|
|
||||||
|
let note_caption = `# Raindar Update\n## ${date}\n${radar_caption}\n\nLeft: Current Observation\nRight: 3 hour forecast`
|
||||||
|
const post_note = Post.create_note(
|
||||||
|
host,
|
||||||
|
access_token,
|
||||||
|
note_text,
|
||||||
|
[static_radar_image__id],
|
||||||
|
"public"
|
||||||
|
)
|
||||||
|
}, 60000); */
|
||||||
})();
|
})();
|
||||||
|
|
||||||
app.listen(port);
|
app.listen(port);
|
||||||
|
|
Loading…
Reference in New Issue