<commit_before>#!/usr/bin/env python
from slackbot.bot import listen_to, respond_to, re
from ..tools import get_html
from .weather import weather_setup


@listen_to('^.g (.*)', re.IGNORECASE)
def google(message, search):
    """
    Performs a google search and returns the href of 1st result
    :param message: Slackbot message object
    :param search: User search string
    :return: Message to slack channel
    """
    search_url = 'https://www.google.com/search?q=' + search
    first_result = get_html(search_url).select('h3.r > a')[0]['href']
    res = re.sub(r'^/url\?q=', '', first_result).split('&sa=', 1)[0]
    return message.send(res)


@listen_to('^.w (\d{5})', re.IGNORECASE)
def weather(message, zip_code):
    """
    TODO: Find good weather API
    :param message:
    :param zip_code:
    :return:
    """
    res = weather_setup(zip_code)
    return message.send('Eh... I\'m workin on it')<commit_msg>cleaned up result URL formatting for slack previews<commit_after>#!/usr/bin/env python
from six.moves.urllib.parse import unquote
from slackbot.bot import listen_to, re
from ..tools import get_html
from .weather import weather_setup


@listen_to('^.g (.*)', re.IGNORECASE)
def google(message, search):
    """
    Performs a google search and returns the href of 1st result
    :param message: Slackbot message object
    :param search: User search string
    :return: Message to slack channel
    """
    search_url = 'https://www.google.com/search?q=' + search
    first_result = get_html(search_url).select('h3.r > a')

    # Skip the first link if it's a google images link
    res = first_result[1]['href'] if 'Images for ' in first_result[0] else first_result[0]['href']

    # Remove google link tracking metadata from URL
    link = re.sub(r'^/url\?q=', '', res).split('&sa=', 1)[0]

    return message.send(unquote(link))


@listen_to('^.w (\d{5})', re.IGNORECASE)
def weather(message, zip_code):
    """
    TODO: Find good weather API
    :param message:
    :param zip_code:
    :return:
    """
    res = weather_setup(zip_code)
    return message.send('Eh... I\'m workin on it')
{'fraction_non_alphanumeric': 0.14373522458628843, 'fraction_numerical': 0.006619385342789598, 'mean_word_length': 3.610021786492375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5264121', 'n_tokens_mistral': 724, 'n_tokens_neox': 693, 'n_words': 201}