LoginSignup
0
0

More than 5 years have passed since last update.

riot.js yahoo wether

Posted at

geo.placesに登録されていれば世界中の地名で使える。但しendpointは米国のyahoo

let yw=(place='tokyo')=>{
 let f=encodeURIComponent
 ,o={format: 'json',env: 'store://datatables.org/alltableswithkeys'
     ,q: `select astronomy.sunset from weather.forecast where woeid in (select woeid from geo.places(1) where text="${place}")`
    }
 ,q=Object.keys(o).map(d=>`${d}=${f(o[d])}`).join('&')
 ,b='https://query.yahooapis.com/v1/public/yql'
 ,url=`${b}?${q}`
 ;
 return fetch(url).then(d=>d.json())
}

全部

<script src="//gnjo.github.io/riot.js"></script>
<app></app>
;(function(root){
 var o={bells:{}}
 o.add=async function(name,caller){return o.bells[name]=caller}
 o.call=async function(name,obj){return (o.bells[name])?o.bells[name](obj):null}
 root.bell=o
})(this)
;
let yw=(place='tokyo')=>{
 let f=encodeURIComponent
 ,o={format: 'json',env: 'store://datatables.org/alltableswithkeys'
     ,q: `select astronomy.sunset from weather.forecast where woeid in (select woeid from geo.places(1) where text="${place}")`
    }
 ,q=Object.keys(o).map(d=>`${d}=${f(o[d])}`).join('&')
 ,b='https://query.yahooapis.com/v1/public/yql'
 ,url=`${b}?${q}`
 ;
 return fetch(url).then(d=>d.json())
}
bell.add('sunset',yw) //add api
;
riot.tag(
`app`
,`<input onkeyup={input} value='tokyo' style={style0}></input><pre>{result}</pre>`
,function(opts){
 let self=this
 ,f=(d=>JSON.stringify(d,null,2))
 ,f1=(d)=>{bell.call('sunset',d).then(d=>{ self.result=f(d)})}
 this.style0='outline:none'
 this.input=function(ev){ f1(ev.target.value) }
})
riot.mount('app',{})
;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0