This commit is contained in:
Igor Chubin 2018-12-09 19:39:22 +01:00
commit 26ed9fa28b
9 changed files with 138 additions and 19 deletions

View File

@ -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("/<path:path>")
@ -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:

View File

@ -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):

View File

@ -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

View File

@ -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))))

View File

@ -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)

View File

@ -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:

View File

@ -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('/','_')

View File

@ -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

47
share/translations/dk.txt Normal file
View File

@ -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