From c4d29901185501f73454becbb9bdcd0c7b6b5191 Mon Sep 17 00:00:00 2001 From: Last2014 Date: Mon, 30 Jun 2025 10:47:56 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E6=B0=97=E3=81=8A=E7=9F=A5=E3=82=89?= =?UTF-8?q?=E3=81=9B=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.ts | 6 ++- scripts/weatherNotice.ts | 76 +++++++++++++++++++------------ src/weatherId.ts | 98 ++++++++++++++++++++-------------------- 3 files changed, 101 insertions(+), 79 deletions(-) diff --git a/main.ts b/main.ts index 4805953..a287c1f 100644 --- a/main.ts +++ b/main.ts @@ -5,14 +5,16 @@ import weatherNotice from "./scripts/weatherNotice.js"; import followBack from "./scripts/followBack.js"; +weatherNotice(); + // 時報・フォローバック(毎時) cron.schedule("0 * * * *", () => { timeNotice(); followBack(); }); -// 天気お知らせ(毎日7:00) -cron.schedule("0 7 * * *", () => { +// 天気お知らせ(毎日7:01) +cron.schedule("1 7 * * *", () => { weatherNotice(); }); diff --git a/scripts/weatherNotice.ts b/scripts/weatherNotice.ts index 8456c78..182d98f 100644 --- a/scripts/weatherNotice.ts +++ b/scripts/weatherNotice.ts @@ -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));*/ } diff --git a/src/weatherId.ts b/src/weatherId.ts index af72a7b..4b83fb5 100644 --- a/src/weatherId.ts +++ b/src/weatherId.ts @@ -1,49 +1,49 @@ -export const cityList: { [cityId: string]: string } = { - "016010": "札幌", - "020010": "青森", - "030010": "盛岡", - "040010": "仙台", - "050010": "秋田", - "060010": "山形", - "070010": "福島", - "080010": "水戸", - "090010": "宇都宮", - "100010": "前橋", - "110010": "さいたま", - "120010": "千葉", - "130010": "東京", - "140010": "横浜", - "150010": "新潟", - "160010": "富山", - "170010": "金沢", - "180010": "福井", - "190010": "甲府", - "200010": "長野", - "210010": "岐阜", - "220010": "静岡", - "230010": "名古屋", - "240010": "津", - "250010": "大津", - "260010": "京都", - "270000": "大阪", - "280010": "神戸", - "290010": "奈良", - "300010": "和歌山", - "310010": "鳥取", - "320010": "松江", - "330010": "岡山", - "340010": "広島", - "350010": "山口", - "360010": "徳島", - "370000": "高松", - "380010": "松山", - "390010": "高知", - "400010": "福岡", - "410010": "佐賀", - "420010": "長崎", - "430010": "熊本", - "440010": "大分", - "450010": "宮崎", - "460010": "鹿児島", - "471010": "那覇", -}; +export const cityList: Array = [ + "016010", + "020010", + "030010", + "040010", + "050010", + "060010", + "070010", + "080010", + "090010", + "100010", + "110010", + "120010", + "130010", + "140010", + "150010", + "160010", + "170010", + "180010", + "190010", + "200010", + "210010", + "220010", + "230010", + "240010", + "250010", + "260010", + "270000", + "280010", + "290010", + "300010", + "310010", + "320010", + "330010", + "340010", + "350010", + "360010", + "370000", + "380010", + "390010", + "400010", + "410010", + "420010", + "430010", + "440010", + "450010", + "460010", + "471010", +];