<commit_before>import requests
from urllib.parse import urljoin
from functools import reduce
from cachetools.func import ttl_cache
from .secrets import weather_underground_api_key


_base_url = 'https://api.wunderground.com/api/'


@ttl_cache(500, ttl=720)
def get_weather(location='Russia/Moscow',
                lang='RU',
                features=('conditions','forecast','astronomy')):
    url_parts = (
        f'{weather_underground_api_key}/',
        *(f'{f}/' for f in features),
        f'lang%3A{lang}/',
        'q/',
        f'{location}.json'
    )
    url = reduce(urljoin, url_parts, _base_url)
    r = requests.get(url)
    return r.json()


def wind(mph):
    return '{:.1f}'.format(float(mph) / 3.6).replace('.', ',')


def wind_dir(s, NESW='СВЮЗ'):
    pairs = ((eng, NESW[i]) for i,eng in enumerate('NESW'))
    s = reduce(
        lambda s, pair: str.replace(s, *pair),
        pairs,
        s
    )
    return s


def pressure(mbar):
    return '{:.3f}'.format(float(mbar) / 1000).replace('.', ',')<commit_msg>Fix long wind direction strings<commit_after>import requests
from urllib.parse import urljoin
from functools import reduce
from cachetools.func import ttl_cache
from .secrets import weather_underground_api_key


_base_url = 'https://api.wunderground.com/api/'


@ttl_cache(500, ttl=720)
def get_weather(location='Russia/Moscow',
                lang='RU',
                features=('conditions','forecast','astronomy')):
    url_parts = (
        f'{weather_underground_api_key}/',
        *(f'{f}/' for f in features),
        f'lang%3A{lang}/',
        'q/',
        f'{location}.json'
    )
    url = reduce(urljoin, url_parts, _base_url)
    r = requests.get(url)
    return r.json()


def wind(mph):
    return '{:.1f}'.format(float(mph) / 3.6).replace('.', ',')


def wind_dir(s, NESW='СВЮЗ'):
    if len(s) > 3:
        s = s[0]
    pairs = ((eng, NESW[i]) for i,eng in enumerate('NESW'))
    s = reduce(
        lambda s, pair: str.replace(s, *pair),
        pairs,
        s
    )
    return s


def pressure(mbar):
    return '{:.3f}'.format(float(mbar) / 1000).replace('.', ',')
{'fraction_non_alphanumeric': 0.166195856873823, 'fraction_numerical': 0.015065913370998116, 'mean_word_length': 2.8219424460431655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4354289', 'n_tokens_mistral': 804, 'n_tokens_neox': 756, 'n_words': 159}