confusion

This commit is contained in:
Win 2024-07-12 13:25:47 +07:00
parent 131cb57e13
commit c420610541
3 changed files with 56 additions and 19 deletions

27
src/api/fetch.cjs Normal file
View File

@ -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;

View File

@ -11,13 +11,11 @@ async function create_image(host, access_token, file_path) {
}
});
if(create.status == 200)
return create;
};
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,
mediaIds: media_ids,
visibility: visibility
@ -25,11 +23,9 @@ async function create_note(host, access_token, text, media_ids, visibility) {
headers: {
'Authorization': `Bearer ${access_token}`
}
}).then((response) => {
let data = response.data;
return data;
});
return create;
}
module.exports.create_image = create_image;

View File

@ -2,6 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
import fs from 'node:fs';
import path from 'node:path';
import express from 'express';
import { pipeline } from 'node:stream/promises';
import * as Post from './api/post.cjs';
import * as Auth from './api/auth.cjs';
@ -51,19 +52,32 @@ app.get('/callback', function(req, res) {
access_token = token_file.token;
}
let static_radar_path = path.join(__dirname, '/data/current_radar.jpg');
const static_radar_image = await Post.create_image(host, access_token, static_radar_path);
const static_radar_image__id = static_radar_image.id;
console.log(static_radar_image);
/* setInterval(async function post() {
let static_radar_path = path.join(__dirname, '/data/current_radar.jpg');
const static_radar_image = await Post.create_image(host, access_token, static_radar_path);
const static_radar_image__id = static_radar_image.data.id;
console.log(static_radar_image__id);
/* let note_text = "hello fediverse";
const post_note = await Post.create_note(
host,
access_token,
note_text,
["" + static_radar_image__id],
"public"
) */
return ;
}, 60000); */
/* setInterval(async () => {
let date = new Date().toLocaleString('th-TH');
/* let curr_image_path = path.join(__dirname, '/data/' + date + '.jpg');
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);