Last active
November 4, 2022 17:32
-
-
Save Comamoca/9ef3b040c59e084e42a832517b55d5e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const areas = [ | |
{ | |
name: "甲府市", | |
url: "https://ja.wttr.in/%E7%94%B2%E5%BA%9C?format=j1", | |
}, | |
{ | |
name: "北杜市", | |
url: "https://ja.wttr.in/%E5%8C%97%E6%9D%9C%E5%B8%82?format=j1", | |
}, | |
{ | |
name: "南アルプス市", | |
url: | |
"https://ja.wttr.in/%E5%8D%97%E3%82%A2%E3%83%AB%E3%83%97%E3%82%B9%E5%B8%82?format=j1", | |
}, | |
{ | |
name: "勝沼町", | |
url: "https://ja.wttr.in/%E5%8B%9D%E6%B2%BC%E7%94%BA?format=j1", | |
}, | |
{ | |
name: "大月市", | |
url: "https://ja.wttr.in/%E5%A4%A7%E6%9C%88%E5%B8%82?format=j1", | |
}, | |
{ | |
name: "身延町", | |
url: "https://ja.wttr.in/%E8%BA%AB%E5%BB%B6%E7%94%BA?format=j1", | |
}, | |
{ | |
name: "南部町", | |
url: "https://ja.wttr.in/%E5%8D%97%E9%83%A8%E7%94%BA?format=j1", | |
}, | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { areas } from "https://gist.githubusercontent.com/Comamoca/9ef3b040c59e084e42a832517b55d5e3/raw/45d2af219afcfad94c40086500a1659db03aba5c/areas.ts"; | |
interface Area { | |
name: string; | |
url: string; | |
} | |
interface Wether { | |
wether: string; | |
temp: string; | |
humidity: string; | |
feelsLike: string; | |
} | |
interface AreaWether { | |
name: string; | |
url: string; | |
wether: Wether; | |
} | |
async function getWether(url: string): Promise<Wether> { | |
const responce = await fetch(url); | |
const data = await responce.json(); | |
let wether = data.current_condition[0].lang_ja[0].value; | |
wether = wether.replace("驟雨", "にわか雨"); | |
const result: Wether = { | |
wether: wether, | |
temp: data.current_condition[0].temp_C, | |
humidity: data.current_condition[0].humidity, | |
feelsLike: data.current_condition[0].FeelsLikeC, | |
}; | |
return result; | |
} | |
async function getAreaWether(areas: Array<Area>): Promise<Array<AreaWether>> { | |
const areaData: Array<AreaWether> = []; | |
for (const area of areas) { | |
const data = await getWether(area.url); | |
areaData.push( | |
{ | |
name: area.name as string, | |
url: area.url as string, | |
wether: data as Wether, | |
}, | |
); | |
} | |
return areaData; | |
} | |
console.log(await getAreaWether(areas)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment