From e5ab61dea31d863d4b280d08bc57a1d32c269bae Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Wed, 12 Feb 2020 21:44:56 +0100 Subject: [PATCH] added workaround for python3 (#369) --- lib/location.py | 6 +++++- lib/spark.py | 10 ++++++++-- lib/wttr_line.py | 5 ++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/location.py b/lib/location.py index ec6d714..f931092 100644 --- a/lib/location.py +++ b/lib/location.py @@ -168,7 +168,11 @@ def load_aliases(aliases_filename): aliases_db = {} with open(aliases_filename, 'r') as f_aliases: for line in f_aliases.readlines(): - from_, to_ = line.decode('utf-8').split(':', 1) + try: + from_, to_ = line.decode('utf-8').split(':', 1) + except AttributeError: + from_, to_ = line.split(':', 1) + aliases_db[location_normalize(from_)] = location_normalize(to_) return aliases_db diff --git a/lib/spark.py b/lib/spark.py index 0c7baef..de71527 100644 --- a/lib/spark.py +++ b/lib/spark.py @@ -26,14 +26,20 @@ import re import math import json import datetime -import StringIO +try: + import StringIO +except: + import io as StringIO import requests import diagram import pyjq import pytz import numpy as np -from astral import Astral, Location +try: + from astral import Astral, Location +except ImportError: + pass from scipy.interpolate import interp1d from babel.dates import format_datetime diff --git a/lib/wttr_line.py b/lib/wttr_line.py index 48fb6a1..f632936 100644 --- a/lib/wttr_line.py +++ b/lib/wttr_line.py @@ -17,7 +17,10 @@ import sys import re import datetime import json -from astral import Astral, Location +try: + from astral import Astral, Location +except ImportError: + pass from constants import WWO_CODE, WEATHER_SYMBOL, WIND_DIRECTION from weather_data import get_weather_data import spark