Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Console weather forecast client, print weather for your city (from yandex pogoda)
#!/usr/bin/env coffee
### -----------------------------------
Console weather client
usage: london
----------------------------------- ###
Jsdom = require 'jsdom'
Table = require 'cli-table'
city = process.argv[2]
address = '' + if city then "#{city}/" else ''
selectors =
city: 'div.b-navigation-city h1.b-navigation-city__city'
term_now: 'div.b-widget-current-weather div.b-thermometer div.b-thermometer__now'
term_night: 'div.b-widget-current-weather div.b-thermometer div.b-thermometer__small-temp'
desc_now: 'div.b-widget-current-weather div.b-thermometer div.b-info-item'
pressure: 'div.b-thermometer-info__line:nth-child(1)'
wind: 'div.b-thermometer-info__line:nth-child(2)'
humidity: 'div.b-thermometer-info__line:nth-child(3)'
selectors_next_days =
date: 'div.b-forecast div.b-forecast__day'
desc: 'div.b-forecast div.b-forecast__desc'
term: 'div.b-forecast div.b-forecast__tday'
term_night: 'div.b-forecast div.b-forecast__tnight'
url: address
scripts: ['']
done: (errors, window) ->
$ = window.$
result = {}
for item_key of selectors
result[item_key] = $(selectors[item_key]).text().replace(/\s+/g, " ")
result.forecast = []
for item_key of selectors_next_days
$(selectors_next_days[item_key]).each (i, el) ->
result.forecast[i] = {} unless result.forecast[i]?
result.forecast[i][item_key] = el.textContent
render result
# -------------------------------------------------------------------
render = (weather) ->
console.log "#{} (#{address})"
term_night = if weather.term_night then ", ночью: #{}" else ""
console.log "Сейчас: #{}, #{}#{term_night}"
console.log "#{weather.pressure}"
console.log "#{weather.humidity}"
console.log "#{weather.wind}"
table = new Table
'mid': ''
'left-mid': ''
'mid-mid': ''
'right-mid': ''
head: ['дата', '°C', 'погода', '°C ночью']
colWidths: [12, 5, 45, 10] (item) ->
table.push [, item.term, item.desc, item.term_night]
table_string = table.toString()
console.log table_string


# install node.js
brew install node

# install node libs
npm -g install coffee-script jsdom cli-table colors

# install script
git clone yandex-weather
chmod a+x yandex-weather/

Usage moscow kiev



After change html, script dont work. Use Go program instead -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.