Example #1
0
def rss(inp, say=None):
    "rss <feed> -- Gets the first three items from the RSS feed <feed>."
    limit = 3

    # preset news feeds
    strip = inp.lower().strip()
    if strip == "bukkit":
        feed = "http://dl.bukkit.org/downloads/craftbukkit/feeds/latest-rb.rss"
        limit = 1
    elif strip == "xkcd":
        feed = "http://xkcd.com/rss.xml"
    elif strip == "ars":
        feed = "http://feeds.arstechnica.com/arstechnica/index"
    else:
        feed = inp

    query = "SELECT title, link FROM rss WHERE url=@feed LIMIT @limit"
    result = web.query(query, {"feed": feed, "limit": limit})

    if not result.rows:
        return "Could not find/read RSS feed."

    for row in result.rows:
        title = text.truncate_str(row["title"], 100)
        try:
            link = web.isgd(row["link"])
        except (web.ShortenError, http.HTTPError, http.URLError):
            link = row["link"]
        say(u"{} - {}".format(title, link))
Example #2
0
def rss(inp, message=None):
    """rss <feed> -- Gets the first three items from the RSS feed <feed>."""
    limit = 3

    # preset news feeds
    strip = inp.lower().strip()
    if strip == "bukkit":
        feed = "http://dl.bukkit.org/downloads/craftbukkit/feeds/latest-rb.rss"
        limit = 1
    elif strip == "xkcd":
        feed = "http://xkcd.com/rss.xml"
    elif strip == "ars":
        feed = "http://feeds.arstechnica.com/arstechnica/index"
    elif strip == "xda":
        feed = "http://feeds.feedburner.com/xda-developers/ShsH?format=xml"
    else:
        feed = inp

    query = "SELECT title, link FROM rss WHERE url=@feed LIMIT @limit"
    result = web.query(query, {"feed": feed, "limit": limit})
    print result.raw
    if not result.rows:
        return "Could not find/read RSS feed."

    for row in result.rows:
        title = text.truncate_str(row["title"], 100)
        try:
            link = web.isgd(row["link"])
        except (web.ShortenError, http.HTTPError, http.URLError):
            link = row["link"]
        message(u"{} - {}".format(title, link))
Example #3
0
def stock(inp):
    """stock <symbol> -- gets stock information"""
    sym = inp.strip().lower()

    query = "SELECT * FROM yahoo.finance.quote WHERE symbol=@symbol LIMIT 1"
    quote = web.query(query, {"symbol": sym}).one()

    # if we dont get a company name back, the symbol doesn't match a company
    if quote['Change'] is None:
        return "Unknown ticker symbol: {}".format(sym)

    change = float(quote['Change'])
    price = float(quote['LastTradePriceOnly'])

    if change < 0:
        quote['color'] = "5"
    else:
        quote['color'] = "3"

    quote['PercentChange'] = 100 * change / (price - change)
    # print quote

    return "\x02{Name}\x02 (\x02{symbol}\x02) - {LastTradePriceOnly} " \
           "\x03{color}{Change} ({PercentChange:.2f}%)\x03 " \
           "Day Range: {DaysRange} " \
           "MCAP: {MarketCapitalization}".format(**quote)
Example #4
0
def stock(inp):
    """stock <symbol> -- gets stock information"""
    sym = inp.strip().lower()

    query = "SELECT * FROM yahoo.finance.quote WHERE symbol=@symbol LIMIT 1"
    quote = web.query(query, {"symbol": sym}).one()

    # if we dont get a company name back, the symbol doesn't match a company
    if quote['Change'] is None:
        return "Unknown ticker symbol: {}".format(sym)

    change = float(quote['Change'])
    price = float(quote['LastTradePriceOnly'])

    if change < 0:
        quote['color'] = "5"
    else:
        quote['color'] = "3"

    quote['PercentChange'] = 100 * change / (price - change)
    # print quote

    return u"\x02{Name}\x02 (\x02{symbol}\x02) - {LastTradePriceOnly} " \
           "\x03{color}{Change} ({PercentChange:.2f}%)\x03 " \
           "Day Range: {DaysRange} " \
           "MCAP: {MarketCapitalization}".format(**quote)
Example #5
0
def get_weather(location):
    """uses the yahoo weather API to get weather information for a location"""

    query = "SELECT * FROM weather.bylocation WHERE location=@location LIMIT 1"
    result = web.query(query, {"location": location})

    data = result.rows[0]["rss"]["channel"]

    # wind conversions
    data['wind']['chill_c'] = int(round((int(data['wind']['chill']) - 32) / 1.8, 0))
    data['wind']['speed_kph'] = int(round(float(data['wind']['speed']) * 1.609344))

    # textual wind direction
    direction = data['wind']['direction']
    if direction >= 0 and direction < 45:
        data['wind']['text'] = 'N'
    elif direction >= 45 and direction < 90:
        data['wind']['text'] = 'NE'
    elif direction >= 90 and direction < 135:
        data['wind']['text'] = 'E'
    elif direction >= 135 and direction < 180:
        data['wind']['text'] = 'SE'
    elif direction >= 180 and direction < 225:
        data['wind']['text'] = 'S'
    elif direction >= 225 and direction < 270:
        data['wind']['text'] = 'SW'
    elif direction >= 270 and direction < 315:
        data['wind']['text'] = 'W'
    elif direction >= 315 and direction < 360:
        data['wind']['text'] = 'NW'
    else:
        data['wind']['text'] = 'N'

    # visibility and pressure conversions
    try:
        data['atmosphere']['visibility_km'] = int(round(float(data['atmosphere']['visibility']) * 1.609344))
        data['atmosphere']['visibility_km'] = str(round((float(data['atmosphere']['visibility']) * 33.8637526), 2))
    except ValueError: pass

    # textual value for air pressure
    rising = data['atmosphere']['rising']
    if rising == 0:
        data['atmosphere']['tendancy'] = 'steady'
    elif rising == 1:
        data['atmosphere']['tendancy'] = 'rising'
    elif rising == 2:
        data['atmosphere']['tendancy'] = 'falling'

    # current conditions
    data['item']['condition']['temp_c'] = \
        int(round(((float(data['item']['condition']['temp']) - 32) / 9) * 5))

    # forecasts
    for i in data['item']['forecast']:
        i['high_c'] = \
        int(round(((float(i['high']) - 32) / 9) * 5))
        i['low_c'] = \
        int(round(((float(i['low']) - 32) / 9) * 5))

    return data
Example #6
0
def get_stock_console(inp, q="SELECT * FROM yahoo.finance.quotes WHERE symbol=@symbol LIMIT 1"):
    try:
        query = web.query(q, {"symbol": inp})
        quote = query.one()
    except:
        return None

    return quote
Example #7
0
def answer(inp):
    "answer <query> -- find the answer to a question on Yahoo! Answers"

    query = "SELECT Subject, ChosenAnswer, Link FROM answers.search WHERE query=@query LIMIT 1"
    result = web.query(query, {"query": inp.strip()}).one()

    short_url = web.isgd(result["Link"])

    # we split the answer and .join() it to remove newlines/extra spaces
    answer = text.truncate_str(' '.join(result["ChosenAnswer"].split()), 80)

    return '\x02{}\x02 "{}" - {}'.format(result["Subject"], answer, short_url)
Example #8
0
def answer(inp):
    ".answer <query> -- find the answer to a question on Yahoo! Answers"

    query = "SELECT Subject, ChosenAnswer, Link FROM answers.search WHERE query=@query LIMIT 1"
    result = web.query(query, {"query": inp.strip()}).one()

    short_url = web.isgd(result["Link"])

    # we split the answer and .join() it to remove newlines/extra spaces
    answer = text.truncate_str(' '.join(result["ChosenAnswer"].split()), 80)

    return u'\x02{}\x02 "{}" - {}'.format(result["Subject"], answer, short_url)