
Untitled
By: a guest on
May 1st, 2012 | syntax:
CoffeeScript | size: 1.40 KB | hits: 21 | expires: Never
exec = require('child_process').exec
moment = require 'moment'
class Birthday
constructor: (@time) ->
@planetList = ['sun', 'moon', 'mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune']
@birthday = @formatEpoch @time
create: (callback) ->
@getAllPlanetPositions(callback)
formatEpoch: (time) ->
moment.unix(time).format('MM.DD.YYYY')
getAllPlanetPositions: (callback) =>
for planet, index in @planetList
console.log @cachedBirthday
@[planet] = {}
@getPlanetPosition birthday, planet, index, (planetName, position) =>
@[planetName].degree = @getDegree(position)
@[planetName].sign = @getSign(position)
callback() if index is 9
getPlanetPosition: (birthday, planetName, planetIndex, callback) ->
# cmd = "bin/swetest -edirinclude/ -b #{birthday} -ut 19:00:00 -p #{planet}.."
# Fake the result for now:
cmd = "echo '238'"
exec cmd, (error, stdout, stderr) ->
callback(planetName, stdout)
getSign: (planetPosition) ->
Math.floor planetPosition / 30
getDegree: (planetPosition) ->
planetPosition % 30
thing = new Birthday 1335902670
# If I log the result in the callback I eventually get the data but how do I say, save this object to a database or return it only when all the callbacks are finished?
thing.create: () ->
console.log thing.moon.sign