воскресенье, 31 марта 2013 г.

Виджет погоды awesome wm

Тянем погоду с Яндекса с помощью curl, парсим с помощью grep.
lua не захотел читать напрямую вывод os.execute c помощью :read('*all'), поэтому приходится сохранять результат парсинга в файл и читать из него:

Как модно и молодёжно узнать погоду из консоли:
temp=`curl -s http://pogoda.yandex.ru/moscow/ | grep -o 'b-thermometer__now">[^>]*<' | grep -o ">.*<" || "--"` ;  echo ${temp//[<>]/}

Далее сам код виджета:


-- {{ Yandex weather
--

yandex_weather = {}
yandex_weather.widget = widget({ type = "textbox" })

yandex_weather.update = function()
    curl = os.execute('temp=`curl -s http://pogoda.yandex.ru/
moscow/ | grep -o \'b-thermometer__now">[^>]*<\' | grep -o ">.*<" || "--"` ;  echo ${temp//[<>]/} > /tmp/awesome.yandex.weather')
    local tFile = io.open('/tmp/awesome.yandex.weather')
    if not tFile then return end
    temperature = tFile:read()
    tFile:close()


    yandex_weather.widget.text = temperature 
end


yandex_weather.update()

yandex_w_timer = timer({ timeout = 1800 })
yandex_w_timer:add_signal("timeout", function()
                                   yandex_weather.update()
                               end)
yandex_w_timer:start()
yandex_weather.update()

-- Yandex weather }}

Комментариев нет:

Отправить комментарий