天気お知らせを修正
This commit is contained in:
+48
-28
@@ -1,35 +1,11 @@
|
||||
import * as dotenv from "dotenv";
|
||||
import { cityList } from "../src/weatherId.js";
|
||||
|
||||
import type * as types from "../types";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export default async function weatherNotice() {
|
||||
let weatherResults: string = "";
|
||||
|
||||
for (const [cityId, cityName] of Object.entries(cityList)) {
|
||||
const res = await fetch(
|
||||
`https://weather.tsukumijima.net/api/forecast/city/${cityId}`,
|
||||
);
|
||||
const data = await res.json();
|
||||
|
||||
const today = data.forecasts[0];
|
||||
const weather = today.telop ?? "取得できませんでした";
|
||||
const maxTemp = today.temperature.max?.celsius ?? "取得できませんでした";
|
||||
const minTemp = today.temperature.min?.celsius ?? "取得できませんでした";
|
||||
const chanceOfRain = data.chanceOfRain?.["T06_12"] ?? "取得できませんでした";
|
||||
|
||||
weatherResults = weatherResults +
|
||||
`【${cityName}】\n
|
||||
天気:${weather}\n
|
||||
最高気温:${maxTemp}℃\n
|
||||
最低気温:${minTemp}℃\n
|
||||
降水確率:${chanceOfRain}
|
||||
`;
|
||||
}
|
||||
|
||||
// 返信用ユーズ
|
||||
/*// 仮投稿
|
||||
const resUeuse = await fetch(
|
||||
`https://${process.env.SERVER}/api/ueuse/create`,
|
||||
{
|
||||
@@ -37,8 +13,8 @@ export default async function weatherNotice() {
|
||||
body: JSON.stringify({
|
||||
token: process.env.TOKEN,
|
||||
text: `
|
||||
# 本日の天気\n
|
||||
${weatherResults}
|
||||
本日の天気
|
||||
※タイムラインが埋まるため返信に記載しています
|
||||
`,
|
||||
}),
|
||||
},
|
||||
@@ -46,5 +22,49 @@ export default async function weatherNotice() {
|
||||
|
||||
const ueuseData: types.ueuseCreateApi = await resUeuse.json();
|
||||
|
||||
console.log(JSON.stringify(ueuseData));
|
||||
console.log(JSON.stringify(ueuseData));*/
|
||||
|
||||
|
||||
let weatherResults: string = "";
|
||||
|
||||
for (let i = 0; i < cityList.length; i++) {
|
||||
const res = await fetch(
|
||||
`https://weather.tsukumijima.net/api/forecast/city/${cityList[i]}`,
|
||||
);
|
||||
|
||||
const data = await res.json();
|
||||
const today = data.forecasts[0];
|
||||
|
||||
const weather = today.telop ?? "取得できませんでした";
|
||||
const maxTemp = today.temperature.max?.celsius ?? "取得できませんでした";
|
||||
const minTemp = today.temperature.min?.celsius ?? "取得できませんでした";
|
||||
const chanceOfRain = data.chanceOfRain?.["T06_12"] ?? "取得できませんでした";
|
||||
|
||||
weatherResults = weatherResults +
|
||||
`【${data.location.city} 】\n
|
||||
天気:${weather}\n
|
||||
最高気温:${maxTemp}℃\n
|
||||
最低気温:${minTemp}℃\n
|
||||
降水確率:${chanceOfRain}
|
||||
`;
|
||||
}
|
||||
|
||||
console.log(weatherResults);
|
||||
|
||||
/*// 天気を返信
|
||||
const resReply = await fetch(
|
||||
`https://${process.env.SERVER}/api/ueuse/create`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: process.env.TOKEN,
|
||||
text: weatherResults,
|
||||
replyid: ueuseData.uniqid
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const replyData: types.ueuseCreateApi = await resReply.json();
|
||||
|
||||
console.log(JSON.stringify(replyData));*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user