1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Add language option to prettyweather

This commit is contained in:
Ferenc- 2018-07-20 13:50:47 +02:00
parent 9e06c2b0e5
commit 90f79a18c0
3 changed files with 17 additions and 4 deletions

View File

@ -37,6 +37,7 @@ None.
refreshInterval: 300
unit: "c"
view: 0
language: "en"
```
### Attributes
@ -65,3 +66,7 @@ Values: `F` for Fahrenheit, `C` for Celcius.
`view` <br />
_Optional_ Wttr.in view configuration. <br />
Values: See `curl wttr.in/:help` for more details.
`language` <br />
_Optional_ Wttr.in language configuration. <br />
Values: See `curl wttr.in/:translation` for more details.

View File

@ -163,6 +163,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
</span><span class="w"> </span>refreshInterval<span class="p">:</span><span class="w"> </span><span class="m">300</span><span class="w">
</span><span class="w"> </span>unit<span class="p">:</span><span class="w"> </span><span class="s2">&#34;c&#34;</span><span class="w">
</span><span class="w"> </span>view<span class="p">:</span><span class="w"> </span><span class="m">0</span></code></pre></div>
</span><span class="w"> </span>language<span class="p">:</span><span class="w"> </span><span class="s2">&#34;en&#34;</span></code></pre></div>
<h3 id="attributes">Attributes</h3>
<p><code>city</code> <br />
@ -190,6 +191,10 @@ Values: <code>F</code> for Fahrenheit, <code>C</code> for Celcius.</p>
<em>Optional</em> Wttr.in view configuration. <br />
Values: See <code>curl wttr.in/:help</code> for more details.</p>
<p><code>language</code> <br />
<em>Optional</em> Wttr.in language configuration. <br />
Values: See <code>curl wttr.in/:translation</code> for more details.</p>
</div>
<div class="footer">

View File

@ -10,10 +10,11 @@ import (
type Widget struct {
wtf.TextWidget
result string
unit string
city string
view string
result string
unit string
city string
view string
language string
}
func NewWidget() *Widget {
@ -37,12 +38,14 @@ func (widget *Widget) prettyWeather() {
widget.unit = wtf.Config.UString("wtf.mods.prettyweather.unit", "m")
widget.city = wtf.Config.UString("wtf.mods.prettyweather.city", "")
widget.view = wtf.Config.UString("wtf.mods.prettyweather.view", "0")
widget.language = wtf.Config.UString("wtf.mods.prettyweather.language", "en")
req, err := http.NewRequest("GET", "https://wttr.in/"+widget.city+"?"+widget.view+"?"+widget.unit, nil)
if err != nil {
widget.result = err.Error()
return
}
req.Header.Set("Accept-Language", widget.language)
req.Header.Set("User-Agent", "curl")
response, err := client.Do(req)
if err != nil {