Merge branch 'master' of github.com:chubin/wttr.in

gregdan3/master
Gregory Danielson 4 years ago
commit 26372148b5
No known key found for this signature in database
GPG Key ID: 88D4EF22F6C14CA7

@ -322,6 +322,7 @@ Terminal with inline images protocols support:
| Jexer | X11 | yes | Sixel |
| GNOME Terminal | X11 | [in-progress](https://gitlab.gnome.org/GNOME/vte/-/issues/253) | Sixel |
| alacritty | X11 | [in-progress](https://github.com/alacritty/alacritty/issues/910) | Sixel |
| foot | Wayland | yes | Sixel |
| DomTerm | Web | yes | Sixel |
| Yaft | FB | yes | Sixel |
| iTerm2 | Mac OS X| yes | IIP |

@ -10,7 +10,7 @@ import sys
import os
import jinja2
from flask import Flask, request, send_from_directory
from flask import Flask, request, send_from_directory, send_file
APP = Flask(__name__)
MYDIR = os.path.abspath(
@ -21,6 +21,7 @@ import wttr_srv
from globals import TEMPLATES, STATIC, LISTEN_HOST, LISTEN_PORT
# pylint: enable=wrong-import-position,wrong-import-order
from view.v3 import v3_file
MY_LOADER = jinja2.ChoiceLoader([
APP.jinja_loader,
@ -29,6 +30,13 @@ MY_LOADER = jinja2.ChoiceLoader([
APP.jinja_loader = MY_LOADER
@APP.route('/v3/<string:location>')
def send_v3(location):
filepath = v3_file(location)
if filepath.startswith("ERROR"):
return filepath.rstrip("\n") + "\n"
return send_file(filepath)
@APP.route('/files/<path:path>')
def send_static(path):
"Send any static file located in /files/"

@ -33,6 +33,8 @@ The map view currently supports three formats:
| Jexer | X11 | yes | Sixel |
| GNOME Terminal | X11 | [in-progress](https://gitlab.gnome.org/GNOME/vte/-/issues/253) | Sixel |
| alacritty | X11 | [in-progress](https://github.com/alacritty/alacritty/issues/910) | Sixel |
| st | X11 | [stixel](https://github.com/vizs/stixel) or [st-sixel](https://github.com/galatolofederico/st-sixel) | Sixel |
| Konsole | X11 | [requested](https://bugs.kde.org/show_bug.cgi?id=391781) | Sixel |
| DomTerm | Web | yes | Sixel |
| Yaft | FB | yes | Sixel |
| iTerm2 | Mac OS X| yes | IIP |
@ -40,6 +42,8 @@ The map view currently supports three formats:
| Windows Terminal | Windows | [in-progress](https://github.com/microsoft/terminal/issues/448) | Sixel |
| [RLogin](http://nanno.dip.jp/softlib/man/rlogin/) | Windows | yes | Sixel | |
Support in all VTE-based terminals: termite, terminator, etc is more or less the same as in the GNOME Terminal
## Notes
### xterm/uxterm

@ -24,6 +24,10 @@ GEOIP_READER = geoip2.database.Reader(GEOLITE)
COUNTRY_MAP = {"Russian Federation": "Russia"}
def _debug_log(s):
with open("/tmp/debug.log", "a") as f:
f.write(s+"\n")
def ascii_only(string):
"Check if `string` contains only ASCII symbols"
@ -100,7 +104,6 @@ def ipcachewrite(ip_addr, location):
cachefile = os.path.join(IP2LCACHE, ip_addr)
if not os.path.exists(IP2LCACHE):
os.makedirs(IP2LCACHE)
with open(cachefile, 'w') as file:
file.write(location[3] + ';' + location[2] + ';' + location[1] + ';' + location[0] + ';' + location[4] + ';' + location[5])
# like ip2location format

@ -28,6 +28,7 @@ import pytz
from constants import WWO_CODE, WEATHER_SYMBOL, WIND_DIRECTION, WEATHER_SYMBOL_WIDTH_VTE
from weather_data import get_weather_data
from . import v2
from . import v3
from . import prometheus
PRECONFIGURED_FORMAT = {
@ -341,11 +342,14 @@ def format_weather_data(query, parsed_query, data):
return prometheus.render_prometheus(data['data'])
if format_line[:2] == "v2":
return v2.main(query, parsed_query, data)
if format_line[:2] == "v3":
return v3.main(query, parsed_query, data)
current_condition = data['data']['current_condition'][0]
current_condition['location'] = parsed_query["location"]
current_condition['override_location'] = parsed_query["override_location_name"]
output = render_line(format_line, current_condition, query)
output = output.rstrip("\n").replace(r"\n", "\n")
return output
def wttr_line(query, parsed_query):
@ -358,7 +362,7 @@ def wttr_line(query, parsed_query):
data = get_weather_data(location, lang)
output = format_weather_data(query, parsed_query, data)
return output.rstrip("\n").replace(r"\n", "\n")
return output
def main():
"""

@ -133,7 +133,7 @@ def get_answer_language_and_view(request):
hostname = request.headers['Host']
if hostname != 'wttr.in' and hostname.endswith('.wttr.in'):
lang = hostname[:-8]
if lang.startswith("v2"):
if lang.startswith("v2") or lang.startswith("v3"):
view_name = lang
lang = None
@ -155,7 +155,9 @@ def get_output_format(query, parsed_query):
Return new location (can be rewritten)
"""
if ('view' in query and not query["view"].startswith("v2")) \
if ('view' in query
and not query["view"].startswith("v2")
and not query["view"].startswith("v3")) \
or parsed_query.get("png_filename") \
or query.get('force-ansi'):
return False
@ -215,18 +217,19 @@ def _response(parsed_query, query, fast_mode=False):
output = get_wetter(parsed_query)
if parsed_query.get('png_filename'):
# originally it was just a usual function call,
# but it was a blocking call, so it was moved
# to separate threads:
#
# output = fmt.png.render_ansi(
# output, options=parsed_query)
result = TASKS.spawn(fmt.png.render_ansi, cache._update_answer(output), options=parsed_query)
output = result.get()
if parsed_query.get("view") != "v3":
# originally it was just a usual function call,
# but it was a blocking call, so it was moved
# to separate threads:
#
# output = fmt.png.render_ansi(
# output, options=parsed_query)
result = TASKS.spawn(fmt.png.render_ansi, cache._update_answer(output), options=parsed_query)
output = result.get()
else:
if query.get('days', '3') != '0' \
and not query.get('no-follow-line') \
and ((parsed_query.get("view") or "v2")[:2] in ["v2"]):
and ((parsed_query.get("view") or "v2")[:2] in ["v2", "v3"]):
if parsed_query['html_output']:
output = add_buttons(output)
else:

@ -29,9 +29,11 @@ Opciones de visualización:
?0 # solamente el clima actual
?1 # el clima actual + la previsión de 1 día
?2 # el clima actual + la previsión de 2 días
?A # ignora al agente del usuario y fuerza el formato de salida ANSI (terminal)
?F # no muestra la linea de "Seguir"
?n # versión corta (solo el día y la noche)
?q # versión silenciosa (sin el texto de "El tiempo en")
?Q # versión supersilenciosa (ni "El tiempo en" ni el nombre de la ciudad)
?Q # versión super silenciosa (sin "El tiempo en" ni el nombre de la ciudad)
?T # desactiva las secuencias de terminal (sin colores)
Opciones de PNG:

@ -1,4 +1,4 @@
114: Claro: Clear
114: Despejado: Clear
113: Soleado: Sunny
116: Parcialmente nublado: Partly cloudy
119: Nublado: Cloudy
@ -10,7 +10,7 @@
185: Posible llovizna helada irregular: Patchy freezing drizzle possible
200: Posibles brotes de tormentas: Thundery outbreaks possible
227: Nieve tormentosa: Blowing snow
230: Tormenta de nieve: Blizzard
230: Ventisca: Blizzard
248: Niebla: Fog
260: Niebla helada: Freezing fog
263: Llovizna ligera irregular: Patchy light drizzle
@ -21,27 +21,27 @@
296: Lluvia ligera: Light rain
299: Lluvia moderada ocasional: Moderate rain at times
302: Lluvia moderada: Moderate rain
305: LLuvia fuerte ocasional: Heavy rain at times
305: Lluvia fuerte ocasional: Heavy rain at times
308: Lluvia fuerte: Heavy rain
311: Lluvia ligera helada: Light freezing rain
314: Lluvia helada moderada o fuerte: Moderate or heavy freezing rain
317: Aguanieve ligero: Light sleet
320: Aguanieve moderado o fuerte: Moderate or heavy sleet
323: Nieve ligera irregular: Patchy light snow
326: Nieve ligera: Light snow
329: Nieve moderada irregular: Patchy moderate snow
332: Nieve moderada: Moderate snow
335: Nieve pesada irregular: Patchy heavy snow
338: Nieve pesada: Heavy snow
350: Gránulos de hielo: Ice pellets
323: Nevada ligera irregular: Patchy light snow
326: Nevada ligera: Light snow
329: Nevada moderada irregular: Patchy moderate snow
332: Nevada moderada: Moderate snow
335: Nevada pesada irregular: Patchy heavy snow
338: Nevada intensa: Heavy snow
350: Granizo: Ice pellets
353: Aguacero ligero: Light rain shower
356: Aguacero moderada o fuerte: Moderate or heavy rain shower
359: Aguacero torrencial: Torrential rain shower
362: Aguacero ligero con aguanieve: Light sleet showers
365: Aguacero con aguanieve moderado o fuerte: Moderate or heavy sleet showers
368: Aguacero con nieve ligero: Light snow showers
371: Aguacero con nieve moderado o fuerte: Moderate or heavy snow showers
368: Aguacero con nieve ligera: Light snow showers
371: Aguacero con nieve moderada o fuerte: Moderate or heavy snow showers
386: Lluvia ligera irregular con truenos: Patchy light rain with thunder
389: Lluvia moderada o fuerte con truenos: Moderate or heavy rain with thunder
392: Nieve ligera irregular con truenos: Patchy light snow with thunder
395: Nieve moderada o fuerte con truenos: Moderate or heavy snow with thunder
392: Nevada ligera irregular con truenos: Patchy light snow with thunder
395: Nevada moderada o fuerte con truenos: Moderate or heavy snow with thunder

Loading…
Cancel
Save