# -*- coding: utf-8 -*-
#!/usr/bin/python

import sys, os, re
import urllib2
import json

def results(parsed, original_query):
    number = parsed.get('number', '')
    number = re.sub(r'[^0-9]', '', number)
    if not number:
        return {}
    url = 'http://data.haoma.sogou.com/vrapi/query_number.php?number=%s&type=json&callback=show' % number
    response = urllib2.urlopen(url).read()
    matches = re.findall(r'{[^}]*}', response)
    title = 'Unknown number'
    if matches:
        result = json.loads(matches[0])
        error_code = result.get('errorCode', 0)
        amount = int(result.get('Amount', 0))
        num_info = result.get('NumInfo')
        info = num_info.split(u'：')
        if len(info) > 1:
            if amount > 0:
                title = '%s (%s, %d reports)' % (info[0], info[1], amount)
            else:
                title = '%s (%s)' % (info[0], info[1])
        else:
            title = '%s' % (num_info)
    return {
        "title": title,
    }

@@ -951,39 +951,1040 @@
     
-return %7B%0A        %22title%22: title
+style = u'''%0A    %3Cstyle%3E%0A    * %7B%0A        padding: 0;%0A        margin: 0;%0A    %7D%0A    html, body, body %3E div %7B%0A        margin: 0;%0A        width: 100%25;%0A        height: 100%25;%0A        font-family: %22HelveticaNeue-Light%22, %22Helvetica Neue Light%22, %22Helvetica Neue%22, Helvetica, Arial;%0A        line-height: 1.2;%0A    %7D%0A    h1, h2, h3, h4, h5 %7B%0A        font-family: %22HelveticaNeue-Light%22, %22Helvetica Neue Light%22, %22Helvetica Neue%22, Helvetica, Arial, %22HiraginoSansGB-W6%22, %22Hiragino Sans GB W6%22;%0A    %7D%0A    h1 %7B%0A        font-size: 32px;%0A    %7D%0A    h1.number %7B%0A        border-bottom: #ddd 1px solid;%0A        padding: 0px 0px 10px 0px;%0A        margin: 0px 0px 10px 0px;%0A        color: #444;%0A    %7D%0A    h3 %7B%0A        font-size: 15px;%0A        color: #888;%0A    %7D%0A    div.content %7B%0A        padding: 15px;%0A    %7D%0A    %3C/style%3E%0A    '''%0A    html = u'%3Cdiv class=%22body%22%3E%3Cdiv class=%22content%22%3E%3Ch1 class=%22number%22%3E%25(number)s%3C/h1%3E%3Ch3%3E%25(title)s%3C/h3%3E%3C/div%3E%3C/div%3E' %25 dict(number=number, title=title)%0A    return %7B%0A        %22title%22: title,%0A        %22html%22: '%25s%25s' %25 (style, html)
 ,%0A  

add html output