#!/usr/bin/env python3

# http://inamidst.com/saxo/
# Created by Sean B. Palmer

import urllib.parse
import saxo

@saxo.command()
def news(arg):
    url = "https://www.bing.co.uk/news/search?q=" + urllib.parse.quote(arg)
    page = saxo.request(url)
    text = page["text"]
    if 'target="_blank" class="imagelink" href="' in text:
        a, b = text.split('target="_blank" class="imagelink" href="', 1)
        return b.split('"', 1)[0]
    return "Sorry, no news about that"
