sq6jnx / sr0wx.py

Automatic hamradio weather station written in python
Apache License 2.0
13 stars 4 forks source link

`pl_google` should be a class #20

Closed sq6jnx closed 9 years ago

sq6jnx commented 9 years ago
  1. Shouldn't code be in __init__?
  2. pl_google should be a class
  3. in a commit which I'm going to make in a minute there will be a block in get_data():
# What a mess!
# TODO: lang.read_temperature_celsius
# TODO: lang.`read datetime function` (no idea for name and
# functionality now)
# TODO: lang.read_pressure
# TODO: read_wind_direction (see def __wind_direction() above)
# TODO: read_wind_direction_degrees
# TODO: read_speed_kmph
# TODO: and so on to clear this mess below.

HINT: first add methods to "prototype" / parent class, each of which will raise NotImplementedError.

sq6jnx commented 9 years ago

HINT#2: add decorator to remove diacritics accents HINT#3: add function/method/lambda to remove spaces in weather codes dictionary

sq6jnx commented 9 years ago

Not pretty, but works with ł and Ł:

# -*- coding: utf-8 -*-
from six import u
from functools import wraps

def remove_accents(function):
    """ unicodedata.normalize() doesn't work with ł and Ł"""
    @wraps(function)
    def wrapper(*args, **kwargs):
        return function(*args, **kwargs)\
            .replace(u("ą"), "a")\
            .replace(u("ć"), "c")\
            .replace(u("ę"), "e")\
            .replace(u("ł"), "l")\
            .replace(u("ń"), "n")\
            .replace(u("ó"), "o")\
            .replace(u("ś"), "s")\
            .replace(u("ź"), "z")\
            .replace(u("ż"), "z")
    return wrapper

@remove_accents
def test():
    return u("Zażółcić gęślą jaźń ZAZÓŁCIĆ GĘŚLĄ JAŹŃ")

print(test())
print(test.__name__)
print(test.__doc__)
sq6jnx commented 9 years ago

I believe I fixed it.