Skip to content

Commit f0cb75f

Browse files
committed
refactor: extract WeatherAPI widget into its own
This was done to allow for choice. In the first step I copied over the existing code into a new folder and accompanied it with icons and locales. There is no indicator of night in the JSON responses, which made me delete the respective icons. I copied and updated the README to fit the current implementation. I will need to add screenshots before I can ask for another round of review. Signed-off-by: André Jaenisch <[email protected]>
1 parent 9abce7f commit f0cb75f

24 files changed

+554
-0
lines changed

weather-api-widget/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# WeatherAPI widget
2+
3+
The widget consists of one section:
4+
- current weather, including humidity, wind speed, UV index
5+
6+
## Customization
7+
8+
It is possible to customize widget by providing a table with all or some of the
9+
following config parameters:
10+
11+
| Name | Default | Description |
12+
|---|---|---|
13+
| coordinates | Required | Table with two elements: latitude and longitude, e.g. `{46.204400, 6.143200}` |
14+
| api_key | Required | [Follow the documentation](https://www.weatherapi.com/docs/) |
15+
| font_name | `beautiful.font:gsub("%s%d+$", "")` | **Name** of the font to use e.g. 'Play' |
16+
| units | `metric` | `metric` for celsius, `imperial` for fahrenheit |
17+
| icon_pack_name | `weather-underground-icons` | Name of the icon pack, could be `weather-underground-icon` or `VitalyGorbachev` or create your own, more details below |
18+
| icons_extension | `.png` | File extension of icons in the pack |
19+
| timeout | 120 | How often in seconds the widget refreshes |
20+
21+
### Icons:
22+
23+
The widget comes with two predefined icon packs:
24+
25+
- [weather-underground-icons](https://github.com/manifestinteractive/weather-underground-icons)
26+
- [VitalyGorbachev](https://www.flaticon.com/authors/vitaly-gorbachev)
27+
28+
To add your custom icons, create a folder with the pack name under `/icons` and
29+
use the folder name in widget's config. There should be 18 icons, preferably
30+
128x128 minimum. Icons should also respect the naming convention, please check
31+
widget's source.
32+
33+
### Examples:
34+
35+
#### Custom font, icons
36+
37+
```lua
38+
weather_api_widget({
39+
api_key='<your-key>',
40+
coordinates = {45.5017, -73.5673},
41+
units = 'imperial',
42+
font_name = 'Carter One',
43+
icons = 'VitalyGorbachev',
44+
icons_extension = '.svg',
45+
}),
46+
```
47+
48+
#### Only current weather
49+
50+
```lua
51+
weather_api_widget({
52+
api_key='<your-key>',
53+
coordinates = {45.5017, -73.5673},
54+
}),
55+
```
56+
57+
## Installation
58+
59+
1. Download json parser for lua from
60+
[github.com/rxi/json.lua](https://github.com/rxi/json.lua) and place it
61+
under **~/.config/awesome/**
62+
(don't forget to star a repo <i class="fa fa-github-alt"></i> ):
63+
64+
```bash
65+
wget -P ~/.config/awesome/ https://raw.githubusercontent.com/rxi/json.lua/master/json.lua
66+
```
67+
68+
1. Clone this repo under **~/.config/awesome/**:
69+
70+
```bash
71+
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
72+
```
73+
74+
1. [Get Weather API key](https://www.weatherapi.com/docs/).
75+
76+
1. Require weather widget at the beginning of **rc.lua**:
77+
78+
```lua
79+
local weather_api_widget = require("awesome-wm-widgets.weather-api-widget.weather")
80+
```
81+
82+
1. Add widget to the tasklist:
83+
84+
```lua
85+
s.mytasklist, -- Middle widget
86+
{ -- Right widgets
87+
layout = wibox.layout.fixed.horizontal,
88+
...
89+
--default
90+
weather_api_widget({
91+
api_key='<your-key>',
92+
coordinates = {45.5017, -73.5673},
93+
}),
94+
,
95+
--customized
96+
weather_api_widget({
97+
api_key='<your-key>',
98+
coordinates = {45.5017, -73.5673},
99+
units = 'imperial',
100+
font_name = 'Carter One',
101+
icons = 'VitalyGorbachev',
102+
icons_extension = '.svg',
103+
}),
104+
...
105+
```
106+
107+
## How it works
108+
109+
The widget calls the API repeatedly in the specified intervals. The JSON
110+
response is parsed and interpreted to build the popup.
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)