My configuration files for Debian/Ubuntu applications
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

weather.md 5.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ## Usage
  2. [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
  3. ### Description
  4. Provides current weather status widgets and X-days forecast pop-up notifications.
  5. Powered by OpenWeatherMap. Obtain a free API key [here](http://openweathermap.org/api) and set it as the `APPID` argument.
  6. By default, it uses [current](http://openweathermap.org/current) for current weather data and [forecast16](http://openweathermap.org/forecast16) for forecasts.
  7. ```lua
  8. local myweather = lain.widget.weather()
  9. ```
  10. ## Input table
  11. Variable | Meaning | Type | Default
  12. --- | --- | --- | ---
  13. `APPID` | API key | String | `nil`
  14. `timeout` | Refresh timeout seconds for current weather status | number | 900 (15 min)
  15. `current_call` | Command to fetch weather status data from the API | string | see `default_current_call`
  16. `forecast_call` | Command to fetch forecast data from the API | string | see `default_forecast_call`
  17. `city_id` | API city code | number | not set
  18. `units` | Temperature units system | string | "metric"
  19. `lang` | API data localization | string | "en"
  20. `cnt` | Forecast days interval | integer | 5
  21. `icons_path` | Icons path | string | `lain/icons/openweathermap`
  22. `notification_preset` | Preset for notifications | table | empty table
  23. `notification_text_fun` | Function to format forecast notifications | function | see `notification_text_fun` below
  24. `weather_na_markup` | Markup to be used when weather textbox is not available | text | " N/A "
  25. `followtag` | Display the notification on currently focused screen | boolean | false
  26. `showpopup` | Display popups with mouse hovering | string, possible values: "on", "off" | "on"
  27. `settings` | User settings | function | empty function
  28. `widget` | Widget to render | function | `wibox.widget.textbox`
  29. - ``default_current_call``
  30. `"curl -s 'http://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'"`
  31. You can rewrite it using any fetcher solution you like, or you can modify it in order to fetch data by city name, instead of ID: just replace `id` with `q`:
  32. `"curl -s 'http://api.openweathermap.org/data/2.5/weather?q=%s&units=%s&lang=%s&APPID=%s'"`
  33. and set `city_id` with your city name, for instance `city_id = "London,UK"`.
  34. - ``default_forecast_call``
  35. `"curl -s 'http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&APPID=%s'"`
  36. Like above.
  37. - ``city_id``
  38. An integer that defines the OpenWeatherMap ID code of your city.
  39. To obtain it go to [OpenWeatherMap](http://openweathermap.org/) and query for your city in the top search bar. The link will look like this:
  40. http://openweathermap.org/city/2643743
  41. your `city_id` is the number at the end.
  42. - ``units``
  43. - For temperature in Fahrenheit use `units = "imperial"`
  44. - For temperature in Celsius use `units = "metric"` (Lain default)
  45. - For temperature in Kelvin use `units = "standard"` (OpenWeatherMap default)
  46. - ``lang``
  47. See *Multilingual Support* section [here](http://openweathermap.org/current).
  48. - ``icons_path``
  49. You can set your own icons path if you don't wish to use `lain/icons/openweathermap`. Just be sure that your icons are PNGs and named exactly like [OpenWeatherMap ones](http://openweathermap.org/weather-conditions).
  50. - ``notification_preset``
  51. Notifications preset table. See [here](https://awesomewm.org/doc/api/libraries/naughty.html#notify) for the details.
  52. - ``notification_text_fun``
  53. ```lua
  54. function (wn)
  55. local day = os.date("%a %d", wn["dt"])
  56. local temp = math.floor(wn["main"]["temp"])
  57. local desc = wn["weather"][1]["description"]
  58. return string.format("<b>%s</b>: %s, %d ", day, desc, temp)
  59. end
  60. ```
  61. - ``followtag``
  62. With multiple screens, the default behaviour is to show a visual notification pop-up window on the first screen. By setting `followtag` to `true` it will be shown on the currently focused tag screen.
  63. - ``settings``
  64. In your `settings` function, you can use `widget` variable to refer to the textbox, and the dictionary `weather_now` to refer to data retrieved by `current_call`. The dictionary is built with [dkjson library](http://dkolf.de/src/dkjson-lua.fsl/home), and its structure is defined [here](http://openweathermap.org/weather-data).
  65. For instance, you can retrieve current weather status and temperature in this way:
  66. ```lua
  67. descr = weather_now["weather"][1]["description"]:lower()
  68. units = math.floor(weather_now["main"]["temp"])
  69. ```
  70. ## Output table
  71. Variable | Meaning | Type
  72. --- | --- | ---
  73. `widget` | The widget | `wibox.widget.textbox`
  74. `icon` | The icon | `wibox.widget.imagebox`
  75. `update` | Update `widget` | function
  76. `timer` | The widget timer | [`gears.timer`](https://awesomewm.org/doc/api/classes/gears.timer.html)
  77. `timer_forecast` | The forecast notification timer | [`gears.timer`](https://awesomewm.org/doc/api/classes/gears.timer.html)
  78. ## Functions
  79. You can attach the forecast notification to any widget like this:
  80. ```lua
  81. myweather.attach(obj)
  82. ```
  83. Hovering over ``obj`` will display the notification.
  84. ## Key bindings
  85. You can create a key binding for the weather pop-up like this:
  86. ```lua
  87. awful.key( { "Mod1" }, "w", function () myweather.show(5) end )
  88. ```
  89. Where the ``show`` argument is an integer defining timeout seconds.