Giter Site home page Giter Site logo

jmatenki's Introduction

jmatenki

気象庁サイト(http://www.jma.go.jp/)から天気予報の情報を取得してオブジェクト形式で返します。

使用方法

下記のような感じでgetWeather()関数に、都道府県名とエリア(北部、南部など)を指定して呼び出します。

const jmatenki = require('jmatenki');

async function main() {
    const tenki = jmatenki();
    const forecast = await tenki.getWeather('奈良県', '北部');
    console.dir(forecast, {depth:null});
}

main();

getWeather()関数の返値で、下記のようなオブジェクト形式の天気予報が取得できます。

{
  prefecture: '奈良県',
  area: '北部',
  daily: [
    {
      forecast: '西の風 後 東の風 晴れ',
      rain: [ { time: '12-24', percent: '0%' } ],
      temp: { max: '11度' }
    },
    {
      forecast: '東の風 後 北の風 くもり 夕方 から 晴れ',
      rain: [ { time: '00-24', percent: '0%' } ],
      temp: { min: '1度', max: '12度' }
    },
    {
      forecast: '北の風 後 北西の風 晴れ'
    }
  ],
  caption: '19日11時奈良地方気象台発表の天気予報(今日19日から明後日21日まで)',
  overview: [
    '天気概況',
    '令和02年2月19日10時34分 奈良地方気象台発表',
    ' 奈良県は、高気圧に覆われておおむね晴れています。',
    ' 19日の奈良県は、高気圧に覆われて晴れるでしょう。',
    ' 20日の奈良県は、気圧の谷の影響で昼過ぎまで曇りますが、夕方からは高気圧に覆われて晴れる見込みです。'
  ]
}
プロパティ 説明
prefecture 都道府県
area エリア
daily 1日ごとの天気予報がセットされた配列です。先頭の要素から、今日、明日、明後日となります。明後日のデータが何もないときは今日、明日の2つの要素となります。
forecast 予報
rain time, percentプロパティを持つ降水確率オブジェクトの配列です。最大で0時~6時、6時~12時、12時~18時、18時~24時の4つが取得できますが、同じ%の時間帯はひとまとめにされます。気象庁サイトの都合上、過去の時間帯や明後日の降水確率は取得できないようです。
temp 最低気温と最高気温です。気象庁サイトの都合上、朝を過ぎると当日の最低気温、また明後日の気温は取得できないようです。
caption 発表日時場所
overview 天気概況を配列に格納します。サイトの改行で要素分割し空行は削除しています。

注意事項

勝手にサイトをスクレイピングしているので、HTMLのレイアウトが変更になった場合は正常に動作しなくなると思われます。

jmatenki's People

Contributors

hisasan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.