Compare commits

..

No commits in common. "6c17683cc26684d7ab5c6f36c22eb57a915cc930" and "5bd251f6eb499144a9cab27c4f2502a0c53ba508" have entirely different histories.

3 changed files with 78 additions and 94 deletions

View File

@ -5,16 +5,14 @@ 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:01) // 天気お知らせ(毎日7:00)
cron.schedule("1 7 * * *", () => { cron.schedule("0 7 * * *", () => {
weatherNotice(); weatherNotice();
}); });

View File

@ -1,11 +1,35 @@
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`,
{ {
@ -13,8 +37,8 @@ export default async function weatherNotice() {
body: JSON.stringify({ body: JSON.stringify({
token: process.env.TOKEN, token: process.env.TOKEN,
text: ` text: `
# \n
${weatherResults}
`, `,
}), }),
}, },
@ -23,42 +47,4 @@ 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));
for (let i = 0; i < cityList.length; i++) {setTimeout(async () => {
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"] ?? "取得できませんでした";
// 天気を返信
const resReply = await fetch(
`https://${process.env.SERVER}/api/ueuse/create`,
{
method: "POST",
body: JSON.stringify({
token: process.env.TOKEN,
text: `
${data.location.city} \n
${weather}\n
${maxTemp}\n
${minTemp}\n
${chanceOfRain}
`,
replyid: ueuseData.uniqid
}),
},
);
const replyData: types.ueuseCreateApi = await resReply.json();
console.log(JSON.stringify(replyData));
}, 500)}
} }

View File

@ -1,49 +1,49 @@
export const cityList: Array<String> = [ export const cityList: { [cityId: string]: 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": "那覇",
]; };