/
weather.coffee
50 lines (39 loc) · 1.24 KB
/
weather.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
options =
city : "Kailua"
region : "HI"
units : 'f'
staticLocation: false
command: "#{process.argv[0]} bottombar/get-weather \
\"#{options.city}\" \
\"#{options.region}\" \
#{options.units} \
#{'static' if options.staticLocation}"
refreshFrequency: 10000
render: (output) ->
data = JSON.parse(output)
channel = data?.query?.results?.channel
return @renderError(data) unless channel
if channel.title == "Yahoo! Weather - Error"
return @renderError(data, channel.item?.title)
weather = channel.item
location = channel.location
date = new Date()
temp = "#{Math.round(weather.condition.temp)}°"
condition = weather.condition.text
location_combined = location.city+', '+location.region
message = "#{condition} #{temp} - #{location_combined}"
"#{message}"
style: """
-webkit-font-smoothing: antialiased
color: #aaa
font: 11px Source Code Pro
right: 140px
bottom: 4px
text-align: right
"""
renderError: (data, message) ->
console.error 'weather widget:', data.error if data?.error
message ?= """
Could not retrieve weather data for #{data.location}.
"""
"#{message}"