Compare commits
2 Commits
5bd251f6eb
...
6c17683cc2
Author | SHA1 | Date |
---|---|---|
|
6c17683cc2 | |
|
c4d2990118 |
6
main.ts
6
main.ts
|
@ -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();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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}
|
※タイムラインが埋まるため返信に記載しています
|
||||||
`,
|
`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -47,4 +23,42 @@ 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)}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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",
|
||||||
};
|
];
|
||||||
|
|
Loading…
Reference in New Issue