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

Line wrapping for "Location"

Open classabbyamp opened this issue 6 years ago • 9 comments

example: http://wttr.in/Paris_1pnF.png

for png generation, can the location line at the bottom be wrapped to the width of the other parts of the image? As it stands now it can lead to inconvenient image dimensions.

classabbyamp avatar Feb 06 '20 06:02 classabbyamp

Yes, it is not good indeed. Should we probably just cut it off?

chubin avatar Feb 17 '20 21:02 chubin

Hmm that might remove useful data on occasion. A hard wrap would better I think, but I'm not sure.

classabbyamp avatar Feb 17 '20 21:02 classabbyamp

maybe, we should remove /([0-9]+;)*/from the full location name? What do you think?

chubin avatar Feb 17 '20 21:02 chubin

That could work, but there might still be very long locations just from the words

classabbyamp avatar Feb 17 '20 21:02 classabbyamp

At least for Paris :)

chubin avatar Feb 17 '20 21:02 chubin

Ok this issue is a bit old but I think I may have somewhat of a solution. Might not be fully complete but I think it's better than it was before. I was thinking it would fit somewhere around here

import textwrap
import re

def _wrap_buf(buf):
    # remove the last line (with the .)
    _buf = buf[:-1]
    # find the max length of everything but the last line (with the the location data)
    cols = max(len(x) for x in _buf[:-1])
    # remove the long string of numbers
    _buf[-1] = re.sub(r"([0-9]+;)+([0-9]+,)? ", "", _buf[-1])
    # use the built-in module textwrap to wrap too-long lines
    for x in _buf:
        if len(x) > cols:
            _buf[-1] = textwrap.fill(_buf[-1], width=cols, replace_whitespace=False, subsequent_indent="  ")
    # re-add that last line
    pbuf.append(" "*(cols+1) + ".")

    return _buf

classabbyamp avatar Sep 24 '20 06:09 classabbyamp

@classabbyamp it looks interesting;

let us test it with several real locations, what do you think? We should test how it handles different languages, especially RTL languages, and language with complex writing scripts, like Devangari etc. If it will not work with them, we could use this implementation at least for Latin/Cyrillic/Greek scripts

chubin avatar Oct 13 '20 19:10 chubin

Here is how it looks for Brasilia, DF, Brazil. I feel that there is a lot of secondary information which can be removed. All the lines "Região ... " could possible be removed. I think something like "place", "city", "state", "ZIP", "country", "coordinates" could minimize the amount of information and probably prevent the need for wrapping. Regarding language it seems all good (Portuguese-Brazil).

Brasilia

leaot avatar Nov 07 '21 19:11 leaot

I think the location line must be cut by the width of the main view at some appropriate place for that (like a comma, for example). Also, it should be possible to switch the location line fully off.

chubin avatar Nov 07 '21 19:11 chubin