wttr.in icon indicating copy to clipboard operation
wttr.in copied to clipboard

Oneline output mode?

Open ghost opened this issue 7 years ago • 40 comments
trafficstars

I'd like to use this for my status bars (dvtm and bar) but there doesn't seem to be a clean oneline output mode. Maybe we could specify a format in the header and get data returned back?

ghost avatar Jan 26 '18 19:01 ghost

Yes, it is planned, I wanted to implement it, but now after this request I'll do it even faster. What data would you like to have first?

chubin avatar Jan 26 '18 20:01 chubin

If you want some help I'd be happy to oblige.

I'd like to be able to send a header field like {city} {weather} {temperature} and get a response with the localized data.

ghost avatar Jan 26 '18 20:01 ghost

Yes, it was exactly the plan, but I see one small problem here: what about forecast? I mean how do you want to code forecast period that you want to get?

Probably something like de.wttr.in/Berlin?line_current="weather temp wind" and instead of line_current, you can write line_spark4h, {{line_spark1d, line_spark3d` (spark for sparklines similar to the sparklines in rate.sx; curl rate.sx to see what I mean)

But I'm not sure. It's not really nice. Do you have other ideas may be?

(and thank you very much for your help offer)

chubin avatar Jan 26 '18 20:01 chubin

out of curiosity, is there an update for this? I would like to add it to my bash shell so it outputs the line to my bash terminal when i login to my computer

ghost avatar May 29 '18 20:05 ghost

@poserman Not yet, but it will be released soon and even better, if you are a tmux user, you can add it to your tmux status line

chubin avatar May 29 '18 20:05 chubin

Not a tmux user myself, but that would help people. Thank you for the update.

ghost avatar May 30 '18 11:05 ghost

I just wanted to open the exact same issue. I would be interested in using this in my i3 status bar. Combined with UTF8 characters this could look really great and still be simple:

Berlin: party sunny, 1 hour of sun, between 5-12°, windy, 10% chance of rain

or with UTF8 characters:

Berlin: :partly_sunny: 1h, :thermometer:5-12°, :wind_face: 8-9km/h, ☔10%

Thanks for your work on this in general!

h-2 avatar Oct 17 '18 15:10 h-2

@poserman Not yet, but it will be released soon and even better, if you are a tmux user, you can add it to your tmux status line

Hi chubin ! I would like very much to integrate it in my tmux bar, really excited about this feature :)

patrickelectric avatar Oct 24 '18 23:10 patrickelectric

Hi everybody! Sorry for the silence, I will implement it on this weekend.

chubin avatar Oct 25 '18 07:10 chubin

I've added initial support of oneline output mode.

Please test it:

$ curl wttr.in/Berlin?format=1
 ⛅ +5⁰C
$ curl wttr.in/Berlin?format=4
Berlin:  ⛅ 🌡️+5⁰C 🌬️↓9 km/h
$ curl wttr.in/Berlin?format=%l:+%t
berlin: +5⁰C

How does it work?

To use the oneline mode, specify a special URL parameter format. It can have parameters of two types:

  • number of predefined format string;
  • format string.

Format string is a normal string, where all characters (including Unicode symbols) have their literal meaning, except special sequences starting with %. This sequences are interpreted as special weather data placeholders.

Currently 4 format symbols are supported:

  • t — temperature;
  • w — wind;
  • l — location;
  • c — weather condition symbol.

Format sequences are always starting with % and ending with one of the special characters:

  • %w
  • %2=t

(currently all characters between them are ignored; but they will be used as data symbol options in future).

Example of format strings:

  • It is %c in %l now.
  • %t %w
  • %l: %c %t

There are several preconfigured formats now, but there will be more (feel free to add you own, here or with pull requests):

PRECONFIGURED_FORMAT = {
    '1':    u'%c %t',
    '2':    u'%c 🌡️%t 🌬️%w',
    '3':    u'%l: %c %t',
    '4':    u'%l: %c 🌡️%t 🌬️%w',
}

It is just an initial implementation, and many things are to be implemented yet, but you already can start playing and experimenting with it.

  • Do you like this one line formatter?
  • What features are you missing?

@h-2 Can you please try to integrate it in your i3 status bar? @patrickelectric Can you please try to integrate it in your tmux status line?

chubin avatar Oct 27 '18 22:10 chubin

weatherbar Looks nice already! Thanks!

h-2 avatar Oct 28 '18 14:10 h-2

I was trying to test it here, but curl wttr.in/Berlin\?line\=1 returns the wttr normal output for me.

patrickelectric avatar Oct 28 '18 14:10 patrickelectric

@patrickelectric It is format=, not line=; excuse me for the confusion.

chubin avatar Oct 28 '18 14:10 chubin

Perfect ! ty very much ! screenshot from 2018-10-28 12-31-01

patrickelectric avatar Oct 28 '18 15:10 patrickelectric

@patrickelectric It looks megacool! But we should extend it. For example, currently it shows only current weather, but not weather forecast. Another cool thing to have would be to have weather report for several locations.

Could you please share your code with us? (I mean the wttr.in related part)

@h-2 Hannes, could you please share your config (wttr.in related part) with us too? Let us make a small collection for the documentation.

chubin avatar Oct 28 '18 15:10 chubin

Thank you, I'll try to share my setup soon.

# curl -s wttr.in/Florianopolis\?format\="%c%20%t%20%w"
WEATHER='#(curl -s wttr.in/Florianopolis\?format\="%%c%%20%%t%%20%%w")'
set -g status-right "$WEATHER #[bg=colour239]#[fg=white] %a %b %-d#[fg=colour14] | #[fg=white]%H:%M #[fg=black,bg=colour14] #h "

For a first version, it's awesome already ! Of course que some advanced users will want forecast for the next days, but for a first version is perfect !

patrickelectric avatar Oct 28 '18 16:10 patrickelectric

@patrickelectric Thank you for sharing your config.

Several questions:

  1. Should we use {} instead of % maybe? (or support moth of them?)
  2. Why you use %%20 instead of +?
  3. What do you think about colors in the wttr.in output? I would like to add them.

Now you can specify several locations in one query, they will be rotating in the output (with specified period, 1 sec by default):

wttr.in/London:Berlin:Moscow?format=3&period=20

To use this feature tmux.conf, status-interval should be set:

set -g status-interval 20

It is ok to use 20 sec to test, but for real life it can be set 60 or even more

chubin avatar Oct 28 '18 18:10 chubin

But we should extend it. For example, currently it shows only current weather, but not weather forecast.

Absolutely, that's what I wanted to propose next, as well! maybe current(day-min/day-max) would be a good default format!

Should we use {} instead of % maybe? (or support moth of them?)

I don't care either way

What do you think about colors in the wttr.in output? I would like to add them.

Would be cool!

Now you can specify several locations in one query,

I am not too interested in specifying multiple at once, but did you consider the possibility that one does not give any location and your server resolves the GeoIP to the nearest location? That would be awesome for notebooks!

@h-2 Hannes, could you please share your config (wttr.in related part) with us too? Let us make a small collection for the documentation.

i3status.conf does not support running external command directly so you have to do the following:

First create ~/bin/my_i3status and make it executable:

#!/bin/sh

i3status | while :
do
        read line
        # musicpd
        time=$(mpc status | awk 'NR==2 { print $3 }')
        playing=$(ncmpcpp --current-song="%a - %n - %t (${time})")
        # wttr.in
        weather=$(curl wttr.in/Berlin?format=4)
        # generate actual status bar content by prefixing the above
        echo "$weather | 🎶 $playing | $line" || exit 1
done

And then edit your .config/i3/config:

# ....
bar {
        # run your custom command instead of i3status
        status_command my_i3status
        tray_output primary
        # choose a fallback font that has emojis
        font pango:Fira Code 13, Droid Sans 13
}
# ...

h-2 avatar Oct 29 '18 19:10 h-2

Hi @chubin,

Here is the full script to install and setup my tmux: link

I'm ok with %, but it can add some problem with bash~, some users will need to search for problems related to %->% and ' ' to %20 or +. I manually add the colors in my toolbar so I don't know if a color feature is necessary. And I'm using cron to setup the curl script timer :) I prefer to control each information timer by it.

patrickelectric avatar Oct 29 '18 22:10 patrickelectric

I haven't checked, but is {} actually much better than %? % seems more conventional. Also { and } are actually Bash syntax chars, so I'm not sure they are safer. (I do agree the URL encoding makes the format string with %'s ugly, but can you really avoid it if the field is free-form?)

Just my $0.02...

AloisMahdal avatar Oct 30 '18 04:10 AloisMahdal

On 13. Dec 2018 09:42, Patrick José Pereira wrote:

@chubin the inline output is not working anymore ?

@patrickelectric

It should work. Why?

-- Igor Chubin

chubin avatar Dec 13 '18 18:12 chubin

Is there a way to get the temperature in dirty American units? I don't have the head for metric temperatures.

robojeb avatar Jan 08 '19 17:01 robojeb

@robojeb For the one-line mode?

For the normal mode you just add ?u to the end of query:

curl wttr.in/?u

chubin avatar Jan 08 '19 17:01 chubin

@chubin Yes for the one-line mode. Sorry I should have been more specific. It appears one line mode doesn't take into account location or the ?u specifier.

robojeb avatar Jan 08 '19 17:01 robojeb

@robojeb

If it does not work automatically, just add &u to the list of the parameters, like here:

$ curl 'wttr.in/Nuremberg?format=3&u'
Nuremberg: 🌦 +39⁰F

chubin avatar Jan 08 '19 20:01 chubin

Interesting, I thought I tried that earlier but it didn't seem to work for me.

robojeb avatar Jan 08 '19 20:01 robojeb

@robojeb Yes, it did not work before indeed. I've just implemented it. It should work without &u also by the way (if you are located in the US)

chubin avatar Jan 08 '19 20:01 chubin

Thanks very much!

robojeb avatar Jan 08 '19 20:01 robojeb

I don't think this warrants making another thread but there is an issue with one-line mode. It returns the query instead of the location name. That is, if you query wttr.in like so: wttr.in/jacksonville?format=4

You get output, e.g. jacksonville: ☁️ 🌡️+15⁰C 🌬️↙22 km/h, whereas with the other format modes you would get "Jacksonville, United States of America". This is important because sometimes there is ambiguity with cities having the same name. Perhaps showing state (e.g. Florida) might also be useful.

Out of curiosity I queried wttr.in with wttr.in/etc?format=4 and got the response etc: ⛅️ 🌡️+17⁰C 🌬️↑4 km/h. If your query instead looks like this wttr.in/etc?0, it turns out there is a city called Etchojoa, Mexico.

Cheers.

jherrera avatar Feb 10 '19 09:02 jherrera

@jherrera It is actually intentionally. The problem is that contrary to the normal output, with the line output you often want to embed the output information somewhere (say, tmux status bar); and you want to keep it short. So the idea was to have the same location name in the output as it was specified. And to check, if it is being resolved correctly you can always use the full version.

chubin avatar Feb 10 '19 14:02 chubin

I understand the reasoning behind it. May I suggest adding a way to retrieve the "good" location name? Perhaps with %L (capital L).

jherrera avatar Feb 11 '19 06:02 jherrera

Format doesn't respect "M" option. For example, curl 'wttr.in/?format=2&M' still shows wind speed in km/h instead of m/s.

gitvb avatar Mar 12 '19 11:03 gitvb

@gitvb Thank you for reporting! It should work now:

~$ curl 'wttr.in/London?format=4&M'
London: ⛅️ 🌡️+14°C 🌬️→8.3 m/s
~$ curl 'wttr.in/London?format=4'
London: ⛅️ 🌡️+14°C 🌬️→30 km/h

chubin avatar Mar 15 '19 19:03 chubin

Today I found this while setting up conky. I would prefer to be able to utilize the one-liners for forecast data too. Is this still in the works?

dubl3a avatar May 29 '19 17:05 dubl3a

Thanks for this @chubin, it will be great if we get the rain info too if possible at least the percentage of having rain maybe as %r or something

ahmedelgabri avatar Jun 07 '19 19:06 ahmedelgabri

@dubl3a Yes, it is a very useful feature, and it will be added soon @ahmedelgabri Ahmed, accepted!

chubin avatar Jul 23 '19 20:07 chubin

I've a couple issues that I'd like to see rectified:

  1. The emoji output is fine, but it'd be better if we could disable the variation sequence (converts the text-font version to the icon version).
  2. Colorized one-line output. While most folks will override the colors in a status line, I like the colorization already employed for blue for cold and red for hot, and don't want to implement my own system of interpreting the temperatures/speeds/rain chance to colors.

pagerc avatar Oct 11 '19 16:10 pagerc

Any way to show 3 days forecast in one line ?

brunakov avatar Jul 08 '21 19:07 brunakov

Same here, it would be nice to generate in one line something like: Kazan Sep 18: 9/2C - Sep 19: 10/0C - Sep 20: 9/0C

With day and night temp.

mesb1 avatar Sep 18 '21 15:09 mesb1

Yes, it is #329 It will be added

chubin avatar Oct 31 '21 11:10 chubin