Skip to content

Instantly share code, notes, and snippets.

@eskim
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eskim/d263dff4f6649fe0732b to your computer and use it in GitHub Desktop.
Save eskim/d263dff4f6649fe0732b to your computer and use it in GitHub Desktop.
muninn-receipes
q.longStackSupport = true
Agent.check = ->
url = "http://www.kma.go.kr/wid/queryDFSRSS.jsp?zone=1121585000"
q.nfcall(request, url).then (res)=>
xml = res[0].body
console.log xml
$ = cheerio.load(res[0].body)
selects = "hour day temp tmx tmn wfEn wfKor pop".split(" ")
console.log selects
results = []
$('data').each ->
results.push _.reduce selects, (memo, key)=>
memo[key] = $(@).find(key).text()
memo
, {}
msgs = _.map results, (r)->
{msg: "#{r.hour}시 - #{r.temp}도 (#{r.tmn}/#{r.tmx}) #{r.wfKor} (강수확률:#{r.pop}%)"}
@create_event title: 'weather forecast', items: msgs
.done()
Agent.check = ->
url = "http://m.search.daum.net/search?w=tot&q=%EC%86%8C%EC%85%9C%ED%94%BD"
q.nfcall(request, url).then (res)=>
body = res[1]
$ = cheerio.load(body)
results = []
$('ol.list_info li').each (i, e)->
link = $(@).find('> a').attr('href')
link = require('url').resolve(url, link)
results.push title: $(@).find('em').text(), link: link
payload =
title: "Social Pick"
items: _.map(results, (r)-> msg: "<a href='#{r.link}'>#{r.title}</a>")
@create_event payload
console.log results
# {"id":12,"jsonrpc":"2.0","result":[{"playerid":1,"type":"video"}]}
# {"id":12,"jsonrpc":"2.0","result":{"item":{"label":"264.540p-iCong.avi","type":"unknown"}}}
#
jsonrpc = (method, params = [])->
url = "http://eskim2rock.iptime.org:8080/jsonrpc"
data = {jsonrpc: "2.0", method: method, params:params, id: 1}
q.nsend(request,'post', url, json: data).then (res)->
res[0].body.result
Agent.check = ->
jsonrpc("Player.GetActivePlayers").then (re)=>
if re.length
jsonrpc("Player.GetItem", [re[0].playerid])
else
@log "no playing"
.then (re)=>
@create_event re.item
.done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment