天気お知らせを修正

This commit is contained in:
Last2014 2025-06-30 10:47:56 +09:00
parent 5bd251f6eb
commit c4d2990118
3 changed files with 101 additions and 79 deletions

View File

@ -5,14 +5,16 @@ import weatherNotice from "./scripts/weatherNotice.js";
import followBack from "./scripts/followBack.js"; import followBack from "./scripts/followBack.js";
weatherNotice();
// 時報・フォローバック(毎時) // 時報・フォローバック(毎時)
cron.schedule("0 * * * *", () => { cron.schedule("0 * * * *", () => {
timeNotice(); timeNotice();
followBack(); followBack();
}); });
// 天気お知らせ(毎日7:00) // 天気お知らせ(毎日7:01)
cron.schedule("0 7 * * *", () => { cron.schedule("1 7 * * *", () => {
weatherNotice(); weatherNotice();
}); });

View File

@ -1,35 +1,11 @@
import * as dotenv from "dotenv"; import * as dotenv from "dotenv";
import { cityList } from "../src/weatherId.js"; import { cityList } from "../src/weatherId.js";
import type * as types from "../types"; import type * as types from "../types";
dotenv.config(); dotenv.config();
export default async function weatherNotice() { 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( const resUeuse = await fetch(
`https://${process.env.SERVER}/api/ueuse/create`, `https://${process.env.SERVER}/api/ueuse/create`,
{ {
@ -37,8 +13,8 @@ export default async function weatherNotice() {
body: JSON.stringify({ body: JSON.stringify({
token: process.env.TOKEN, token: process.env.TOKEN,
text: ` text: `
# \n
${weatherResults}
`, `,
}), }),
}, },
@ -46,5 +22,49 @@ export default async function weatherNotice() {
const ueuseData: types.ueuseCreateApi = await resUeuse.json(); 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));*/
} }

View File

@ -1,49 +1,49 @@
export const cityList: { [cityId: string]: string } = { export const cityList: Array<String> = [
"016010": "札幌", "016010",
"020010": "青森", "020010",
"030010": "盛岡", "030010",
"040010": "仙台", "040010",
"050010": "秋田", "050010",
"060010": "山形", "060010",
"070010": "福島", "070010",
"080010": "水戸", "080010",
"090010": "宇都宮", "090010",
"100010": "前橋", "100010",
"110010": "さいたま", "110010",
"120010": "千葉", "120010",
"130010": "東京", "130010",
"140010": "横浜", "140010",
"150010": "新潟", "150010",
"160010": "富山", "160010",
"170010": "金沢", "170010",
"180010": "福井", "180010",
"190010": "甲府", "190010",
"200010": "長野", "200010",
"210010": "岐阜", "210010",
"220010": "静岡", "220010",
"230010": "名古屋", "230010",
"240010": "津", "240010",
"250010": "大津", "250010",
"260010": "京都", "260010",
"270000": "大阪", "270000",
"280010": "神戸", "280010",
"290010": "奈良", "290010",
"300010": "和歌山", "300010",
"310010": "鳥取", "310010",
"320010": "松江", "320010",
"330010": "岡山", "330010",
"340010": "広島", "340010",
"350010": "山口", "350010",
"360010": "徳島", "360010",
"370000": "高松", "370000",
"380010": "松山", "380010",
"390010": "高知", "390010",
"400010": "福岡", "400010",
"410010": "佐賀", "410010",
"420010": "長崎", "420010",
"430010": "熊本", "430010",
"440010": "大分", "440010",
"450010": "宮崎", "450010",
"460010": "鹿児島", "460010",
"471010": "那覇", "471010",
}; ];