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