Skip to content

Instantly share code, notes, and snippets.

@eskim
Created May 7, 2014 10:59
Show Gist options
  • Save eskim/b1acfa7f7bf0c33969c2 to your computer and use it in GitHub Desktop.
Save eskim/b1acfa7f7bf0c33969c2 to your computer and use it in GitHub Desktop.
CAMP_CODES =
"0005": "강동"
"0013": "중랑"
"0012": "자라섬"
Agent.check = ->
true
Agent.receive = (evts)->
@log 'events', evts
aid = evts.agent_id
items = evts.payload.items
@log('receive events')
msgs = [];
e_list = items
qs = _.map items, (e)=>
memKey = [aid, e.PlayDate, e.GroupCode].join(":")
remains = e.ProductRemainCount
@memory(memKey).then (prev)=>
@log(memKey + " : " + prev + ", " + remains)
if !prev or (prev != remains)
msg = [aid, e.PlayDate, e.GroupName, remains].join(" : ")
msgs.push(msg)
@memory(memKey, remains)
q.all(qs).then =>
if msgs.length
@create_event({title: "Huginn", url:"http://huginn.app.esfoo.com", message:msgs.join("\n")})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment