Exemplo n.º 1
0
def weather(query):
    ow_api = 'http://api.openweathermap.org/data/2.5/forecast/city'
    params = {
        'APPID': getWheatApiKey(),
        'units': 'metric',
        'lang': 'sp',
        'q': query
    }
    resp = {'txt': "", 'plot': "", 'status': None, 'error': None}
    if params['APPID']:
        try:
            son = GetJson(ow_api, params)
            Data = GetData(son)
            if 'error' in Data.keys():
                resp[
                    'error'] = 'The api response: {}, try again in few seconds'.format(
                        Data['error'])
                return resp
            else:
                msg = format_msg(son, Data)
                resp['txt'] = msg['Txt_top'] + msg['Txt_full_prev']
                resp['plot'] = PlotAll(Data['datetimes'], Data['Temps'],
                                       Data['humidity'], Data['titleplot'])
                return resp
        except Exception as error:
            resp['error'] = error
            logger.exception('error:', error)
            return resp
    else:
        resp['status'] = "Module Disabled"
        return resp
Exemplo n.º 2
0
def Urbdict(message):
    try:
        url = 'http://api.urbandictionary.com/v0/define?term=%s' % (
            message.text.lstrip('/urbdict '))
        data = GetJson(url)
        text = data['list'][0]['definition']
        return text
    except Exception:
        return 'Definition too long :<'
Exemplo n.º 3
0
def Wiki(m):
    baseurl = 'http://es.wikipedia.org/w/api.php'
    my_atts = {'action': 'opensearch', 'format': 'json', 'limit': 1}
    quest = m.text.strip("/wiki ")
    if quest:
        my_atts['search'] = quest
        data = GetJson(baseurl, my_atts)
        try:
            url = data[3][0]
            return url
        except IndexError:
            return "Mala consulta"
    else:
        return "example: /wiki cats"
Exemplo n.º 4
0
def Imdb(message):
    m = ''
    query = 'http://www.omdbapi.com/?t='
    text1 = message.text.strip('/imdb ')
    query += text1.replace(" ", "+")
    query += '&y=&plot=short&r=json'
    info = GetJson(query)
    try:
        title = info['Title'] + '\n'
        year = info['Year'] + '\n'
        rated = info['Rated'] + '\n'
        released = info['Released'] + '\n'
        runtime = info['Runtime'] + '\n'
        director = info['Director'] + '\n'
        writer = info['Writer'] + '\n'
        actors = info['Actors'] + '\n'
        plot = info['Plot'] + '\n'
        poster = info['Poster']
        m = m + '*Title:* ' + '[' + title + ']' + '(' + poster + ')' + '\n' + '*Year:* ' + year + \
            '*Rated:* ' + rated + '*Released:* ' + released + '*Runtime:* ' + runtime + '*Director:* ' + \
            director + '*Writer:* ' + writer + '*Actors:* ' + actors + '*Plot:* ' + plot
        return m
    except KeyError:
        return 'Nope :('
Exemplo n.º 5
0
def Boobs(number):
    query = 'http://api.oboobs.ru/boobs/' + str(number) + '/1/rank/'
    info = GetJson(query)
    text = 'http://media.oboobs.ru/boobs/' + info[0]['preview'].strip('boobs_preview/')
    return text