mirror of
https://github.com/chubin/wttr.in.git
synced 2024-10-05 01:42:07 +02:00
9d23087ca4
Windows' native terminal, `conhost.exe`, lacks font fallback support. This causes some of the characters used in `wttr.in`'s terminal output to not be displayed at all - placeholders are supplied in their place. This PR provides a mode that, when enabled, translates missing glyphs to ones available on every platform without (*I believe*) making any compromises regarding their meaning; see translation table below. | Character | C-UCP | Replacements | R-UCPs | | :--------------- | :----: | :------------------------------------ | :----: | | NORTH WEST ARROW | U+2196 | BOX DRAWINGS LIGHT ARC DOWN AND LEFT | U+256E | | NORTH EAST ARROW | U+2197 | BOX DRAWINGS LIGHT ARC DOWN AND RIGHT | U+256D | | SOUTH EAST ARROW | U+2198 | BOX DRAWINGS LIGHT ARC UP AND RIGHT | U+2570 | | SOUTH WEST ARROW | U+2199 | BOX DRAWINGS LIGHT ARC UP AND LEFT | U+256F | | HIGH VOLTAGE SIGN | U+26A1 | BOX DRAWINGS LIGHT DOWN AND RIGHT + UP AND LEFT | U+250C + U+2518 |
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
import sys
|
|
|
|
import os
|
|
import dateutil.parser
|
|
|
|
from gevent.subprocess import Popen, PIPE
|
|
|
|
sys.path.insert(0, "..")
|
|
import constants
|
|
import parse_query
|
|
import globals
|
|
|
|
def get_moon(parsed_query):
|
|
|
|
location = parsed_query['orig_location']
|
|
html = parsed_query['html_output']
|
|
lang = parsed_query['lang']
|
|
hemisphere = parsed_query['hemisphere']
|
|
|
|
date = None
|
|
if '@' in location:
|
|
date = location[location.index('@')+1:]
|
|
location = location[:location.index('@')]
|
|
|
|
cmd = [globals.PYPHOON]
|
|
if lang:
|
|
cmd += ["-l", lang]
|
|
|
|
if not hemisphere:
|
|
cmd += ["-s", "south"]
|
|
|
|
if date:
|
|
try:
|
|
dateutil.parser.parse(date)
|
|
except Exception as e:
|
|
print("ERROR: %s" % e)
|
|
else:
|
|
cmd += [date]
|
|
|
|
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
|
stdout = p.communicate()[0]
|
|
stdout = stdout.decode("utf-8")
|
|
|
|
if parsed_query.get('no-terminal', False):
|
|
stdout = globals.remove_ansi(stdout)
|
|
|
|
if parsed_query.get('dumb', False):
|
|
stdout = stdout.translate(globals.TRANSLATION_TABLE)
|
|
|
|
if html:
|
|
p = Popen(
|
|
["bash", globals.ANSI2HTML, "--palette=solarized", "--bg=dark"],
|
|
stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
|
stdout, stderr = p.communicate(stdout.encode("utf-8"))
|
|
stdout = stdout.decode("utf-8")
|
|
stderr = stderr.decode("utf-8")
|
|
if p.returncode != 0:
|
|
globals.error(stdout + stderr)
|
|
|
|
return stdout
|