From bfa1b1c584c4752febace7955c99de4be4cbdc84 Mon Sep 17 00:00:00 2001 From: Kim Schulz Date: Thu, 8 Nov 2018 16:08:33 +0100 Subject: [PATCH 1/2] Added Danish Translation --- share/translations/dk-help.txt | 66 ++++++++++++++++++++++++++++++++++ share/translations/dk.txt | 47 ++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 share/translations/dk-help.txt create mode 100644 share/translations/dk.txt diff --git a/share/translations/dk-help.txt b/share/translations/dk-help.txt new file mode 100644 index 0000000..b07520d --- /dev/null +++ b/share/translations/dk-help.txt @@ -0,0 +1,66 @@ +Brugsanvisning: + + $ curl wttr.in # nuværende lokation + $ curl wttr.in/osl # vejret på Gardermoen flyveplads + +Understøttede lokationsspecifikationer: + + /gistrup # bynavn + /~Aalborg+stadion # valgfri lokation + /Москва # Unicode navn på lokation på alle sprog + /cph # flyvepladskode (3 bogstaver) + /@stackoverflow.com # domønenavn + /94107 # postnummer (kun USA) + /-78.46,106.79 # GPS-koordinater + +Specielle lokationer: + + /moon # Månefase (brug med ,+US eller ,+France for disse lokationer) + /moon@2014-10-26 # Månefase for specifik dato (@2014-10-26) + +Enheder: + + ?m # metrisk (SI) (standard alle steder undtaget i USA) + ?u # USCS (standard i USA) + ?M # vindstyrke i meter per sekund + +Visningsvalg: + + ?0 # kun vejret nu + ?1 # vejret nu + 1 dag + ?2 # vejret nu + 2 dage + ?n # smal visning (kun dag og nat) + ?q # stille visning (ingen "Vejrmelding"-tekst) + ?Q # superstille visning (ingen "Vejrmelding", ingen bynavn) + ?T # ingen terminalsekvenser (ingen farver) + +PNG valg: + + /paris.png # generer en PNG-fil + ?p # tegn ramme på + ?t # gennemsigtighed 150 + transparency=... # gennemsigtighed fra 0 til 255 (255 = ikke gennemsigtigt) + +Tilvalg kan kombineres: + + /Paris?0pq + /Paris?0pq&lang=fr + /Paris_0pq.png # for PNG er filmodus specificeret efter _ + /Rome_0pq_lang=it.png # lange tilvalg separeres med underscore (_) + +Oversættelser: + + $ curl fr.wttr.in/Paris + $ curl wttr.in/paris?lang=fr + $ curl -H "Accept-Language: fr" wttr.in/paris + +Understøttede sprog: + + FULL_TRANSLATION (understøttet) + PARTIAL_TRANSLATION (under udarbejdning) + +Specielle URLer: + + /:help # vis denne side + /:bash.function # vis den foreslåede bash-funktion wttr() + /:translation # vis information om oversætterne diff --git a/share/translations/dk.txt b/share/translations/dk.txt new file mode 100644 index 0000000..35ebdca --- /dev/null +++ b/share/translations/dk.txt @@ -0,0 +1,47 @@ +113: Klart : Clear +113: Sol : Sunny +116: Delvis skyet : Partly cloudy +119: Skyet : Cloudy +122: Overskyet : Overcast +143: Dis : Mist +176: Chance for skiftende regn : Patchy rain possible +179: Chance for skiftende sne : Patchy snow possible +182: Chance for skiftende slud : Patchy sleet possible +185: Chance for skiftende, kold småregn : Patchy freezing drizzle possible +200: Fare for torden : Thundery outbreaks possible +227: Snefygning : Blowing snow +230: Snestorm : Blizzard +248: Tåge : Fog +260: Kold tåge : Freezing fog +263: Skiftende, let støvregn : Patchy light drizzle +266: Let støvregn : Light drizzle +281: Kold støvregn : Freezing drizzle +284: Kraftig, kold regn : Heavy freezing drizzle +293: Skiftende, let regn : Patchy light rain +296: Let regn : Light rain +299: Til tider en smule regn : Moderate rain at times +302: En smule regn : Moderate rain +305: Til tider kraftig regn : Heavy rain at times +308: Kraftig regn : Heavy rain +311: Let, kold regn : Light freezing rain +314: Moderat eller kraftig, kold, regn : Moderate or heavy freezing rain +317: Let slud : Light sleet +320: Moderat eller kraftig slud : Moderate or heavy sleet +323: Byger af let sne : Patchy light snow +326: Let sne : Light snow +329: Byger med moderat sne : Patchy moderate snow +332: Moderat snevej : Moderate snow +335: Byger med kraftigt snefald : Patchy heavy snow +338: Kraftigt snefald : Heavy snow +350: Hagl : Ice pellets +353: Lette regnbyger : Light rain shower +356: Moderat til tunge regnskyl : Moderate or heavy rain shower +359: Styrtregn : Torrential rain shower +362: Lette sludbyger : Light sleet showers +365: Moderat til tunge sludbyger : Moderate or heavy sleet showers +368: Lette snebyger : Light snow showers +371: Moderat til kraftige snebyger : Moderate or heavy snow showers +386: Byger af let regn med torden : Patchy light rain with thunder +389: Moderat eller krafig regn med torden : Moderate or heavy rain with thunder +392: Byger af let sne med torden : Patchy light snow with thunder +395: Moderat til krafitg sne med torden : Moderate or heavy snow with thunder From 7c47cd7d0cba8cac81d798910f71c6484d6530d4 Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 2 Dec 2018 09:41:29 +0100 Subject: [PATCH 2/2] Modernize Python 2 code to get ready for Python 3 --- bin/proxy.py | 13 +++++++------ lib/globals.py | 5 +++-- lib/location.py | 5 +++-- lib/unicodedata2.py | 5 +++-- lib/wttr.py | 3 ++- lib/wttr_srv.py | 4 ++-- lib/wttrin_png.py | 9 +++++---- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/bin/proxy.py b/bin/proxy.py index bfc9fe5..fda7131 100644 --- a/bin/proxy.py +++ b/bin/proxy.py @@ -8,6 +8,7 @@ It caches the answers and handles various data sources transforming their answers into format supported by the wttr.in service. """ +from __future__ import print_function from gevent.pywsgi import WSGIServer from gevent.monkey import patch_all @@ -90,7 +91,7 @@ def translate(text, lang): """ translated = TRANSLATIONS.get(lang, {}).get(text, text) if text.encode('utf-8') == translated: - print "%s: %s" % (lang, text) + print("%s: %s" % (lang, text)) return translated def cyr(to_translate): @@ -111,9 +112,9 @@ def add_translations(content, lang): try: d = json.loads(content) # pylint: disable=invalid-name except ValueError as exception: - print "---" - print exception - print "---" + print("---") + print(exception) + print("---") try: weather_condition = d['data']['current_condition'][0]['weatherDesc'][0]['value'] @@ -159,7 +160,7 @@ def add_translations(content, lang): content = json.dumps(d) except (IndexError, ValueError) as exception: - print exception + print(exception) return content @APP.route("/") @@ -176,7 +177,7 @@ def proxy(path): if content is None: srv = _find_srv_for_query(path, query_string) url = '%s/%s?%s' % (srv, path, query_string) - print url + print(url) attempts = 5 while attempts: diff --git a/lib/globals.py b/lib/globals.py index b10638b..7de6c24 100644 --- a/lib/globals.py +++ b/lib/globals.py @@ -1,6 +1,7 @@ """ global configuration of the project """ +from __future__ import print_function import logging import os @@ -76,7 +77,7 @@ def error(text): "log error `text` and raise a RuntimeError exception" if not text.startswith('Too many queries'): - print text + print(text) logging.error("ERROR %s", text) raise RuntimeError(text) @@ -84,7 +85,7 @@ def log(text): "log error `text` and do not raise any exceptions" if not text.startswith('Too many queries'): - print text + print(text) logging.info(text) def debug_log(text): diff --git a/lib/location.py b/lib/location.py index fde49ee..d89b098 100644 --- a/lib/location.py +++ b/lib/location.py @@ -7,6 +7,7 @@ and basing on this information generates precise location description. """ +from __future__ import print_function import os import json @@ -67,7 +68,7 @@ def geolocator(location): try: geo = requests.get('%s/%s' % (GEOLOCATOR_SERVICE, location)).text except requests.exceptions.ConnectionError as exception: - print "ERROR: %s" % exception + print("ERROR: %s" % exception) return None if geo == "": @@ -77,7 +78,7 @@ def geolocator(location): answer = json.loads(geo.encode('utf-8')) return answer except ValueError as exception: - print "ERROR: %s" % exception + print("ERROR: %s" % exception) return None return None diff --git a/lib/unicodedata2.py b/lib/unicodedata2.py index 8d65283..ed9070e 100644 --- a/lib/unicodedata2.py +++ b/lib/unicodedata2.py @@ -1,3 +1,4 @@ +from __future__ import print_function from unicodedata import * script_data = { @@ -599,7 +600,7 @@ def _compile_scripts_txt(): idx.append((int(a, 16), int(b or a, 16), names.index(name), cats.index(cat))) idx.sort() - print 'script_data = {\n"names":%s,\n"cats":%s,\n"idx":[\n%s\n]}' % ( + print('script_data = {\n"names":%s,\n"cats":%s,\n"idx":[\n%s\n]}' % ( '\n'.join(textwrap.wrap(repr(names), 80)), '\n'.join(textwrap.wrap(repr(cats), 80)), - '\n'.join(textwrap.wrap(', '.join('(0x%x,0x%x,%d,%d)' % c for c in idx), 80))) + '\n'.join(textwrap.wrap(', '.join('(0x%x,0x%x,%d,%d)' % c for c in idx), 80)))) diff --git a/lib/wttr.py b/lib/wttr.py index f8bbcfb..3ba31d9 100644 --- a/lib/wttr.py +++ b/lib/wttr.py @@ -1,5 +1,6 @@ # vim: set encoding=utf-8 +from __future__ import print_function import gevent from gevent.pywsgi import WSGIServer from gevent.queue import Queue @@ -119,7 +120,7 @@ def get_wetter(location, ip, html=False, lang=None, query=None, location_name=No p = Popen(cmd, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() if p.returncode != 0: - print "ERROR: location not found: %s" % location + print("ERROR: location not found: %s" % location) if 'Unable to find any matching weather location to the query submitted' in stderr: if location != NOT_FOUND_LOCATION: NOT_FOUND_MESSAGE_HEADER = u"ERROR: %s: %s\n---\n\n" % (get_message('UNKNOWN_LOCATION', lang), location) diff --git a/lib/wttr_srv.py b/lib/wttr_srv.py index 6590c72..a4e6dd6 100644 --- a/lib/wttr_srv.py +++ b/lib/wttr_srv.py @@ -163,7 +163,7 @@ def wttr(location, request): try: LIMITS.check_ip(ip_addr) - except RuntimeError, exception: + except RuntimeError as exception: return str(exception) png_filename = None @@ -249,7 +249,7 @@ def wttr(location, request): output += '\n' + get_message('FOLLOW_ME', lang).encode('utf-8') + '\n' return output - except RuntimeError, exception: + except RuntimeError as exception: if 'Malformed response' in str(exception) \ or 'API key has reached calls per day allowed limit' in str(exception): if html_output: diff --git a/lib/wttrin_png.py b/lib/wttrin_png.py index 770c668..a84ec0f 100644 --- a/lib/wttrin_png.py +++ b/lib/wttrin_png.py @@ -1,6 +1,7 @@ #!/usr/bin/python #vim: encoding=utf-8 +from __future__ import print_function import sys import os import re @@ -287,9 +288,9 @@ def make_wttr_in_png(png_name, options=None): """ parsed = parse_wttrin_png_name(png_name) - print "------" - print parsed - print "------" + print("------") + print(parsed) + print("------") # if location is MyLocation it should be overriden # with autodetected location (from options) @@ -301,7 +302,7 @@ def make_wttr_in_png(png_name, options=None): if key not in parsed: parsed[key] = val url = make_wttrin_query(parsed) - print "URL = ", url + print("URL = ", url) timestamp = time.strftime("%Y%m%d%H", time.localtime()) cached_basename = url[14:].replace('/','_')