Exemplo n.º 1
0
def dosoup(page,node,context,sibling=False):

    if (sibling):
        doc = page
    else:
        doc = BeautifulSoup(page)

    soupargs = {}
    args = node.attribute.partition(" ")[2]
    n=0
    if (args):
        soupargs = parseargs(args,context)
        for k in soupargs:
            soupargs[k] = dynamic_core.get_var(soupargs[k],context)
        if 'n' in soupargs.keys():
            n=int(soupargs.get('n',0))
            del soupargs['n']
        elif 'list' in soupargs.keys():
            print "dat list"
            name = node.attribute.partition(" ")[0]
            del soupargs['list']
            return doc.findAll(name,soupargs)

    name = node.attribute.partition(" ")[0]
    if sibling == False:
        if n==0:
            return doc.find(name,soupargs)
        else:
            
            return doc.findAll(name,soupargs)[n]
    else:
        return doc.findNextSiblings(name,soupargs)[n]
Exemplo n.º 2
0
def tag_format_html(node,context):
    """[html] - Formats HTML for display in skype."""
    s=''
    if node.type=='tag':
        s = stringsafety.FormatHTML(dynamic_core.get_var(node.attribute,context))
    elif node.type=='cont':
        s= stringsafety.FormatHTML(dynamic_core.stringify(node.process_children(context)))

    if len(s)>550:
        return s[0:447]+"..."
    else:
        return s
Exemplo n.º 3
0
def tag_fetchfm(node,context):
    """[lastfm name] - Fetch lastfm data for name. Returns nothing, but sets the value of [lastfm_success], and possibly [lastfm_album], [lastfm_track], [lastfm_playing], [lastfm_artist] and [lastfm_url]."""
    track = listening(dynamic_core.get_var(node.attribute,context))
    if not track:
        context.vars['lastfm_success']=False
        return ""#[Unable to fetch Last.fm data for %s]"%node.attribute
    context.vars['lastfm_success']=True
    context.vars['lastfm_album']=track['album']['#text']
    context.vars['lastfm_track']=track['name']
    context.vars['lastfm_playing']= ('@attr' in track)
    context.vars['lastfm_artist']=track['artist']['#text']
    context.vars['lastfm_url']=track['url']
Exemplo n.º 4
0
def tag_quoteline(node,context):
    """[quoteline [search]] - Get a random quote line, or a line containing search"""
    q=None
    v = dynamic_core.get_var(node.attribute,context)
    if v:
        q = GetQuoteByString(v)
    else:
        q = GetRandomQuote()
    if q:
        s = q[0][0].split("\n")
        line = s[random.randint(0,len(s)-1)]
        return line.partition(": ")[2].strip()
Exemplo n.º 5
0
def parseargs(args,context):
    args+=" "
    ret={}
    attrib=''
    is_attrib=True
    word=''
    in_quote=0
    quoted=False
    for char in args:
        if char=='"':
            if in_quote==0:
                in_quote=2
                quoted=True
            elif in_quote==2:
                in_quote = 0
            else:
                word+=char
        elif char=="'":
            if in_quote==0:
                in_quote = 1
                quoted=True
            elif in_quote==1:
                in_quote = 0
            else:
                word+=char
        elif char=="=":
            if in_quote==0:
                if is_attrib:
                    
                    attrib = word
                    is_attrib=False
                    word=''
                else:
                    word+=char
            else:
                word+=char
        elif char==" ":
            if in_quote==0:
                if quoted==False:
                    ret[attrib]=dynamic_core.get_var(word,context)
                else:
                    ret[attrib]=word
                is_attrib=True
                quoted=False
                word=''
            else:
                word+=char
        else:
            word+=char

    return ret
Exemplo n.º 6
0
def tag_taghelp(node,context):
    """[taghelp tag] - Returns the documentation for a tag."""
    return get_tag_help(get_var(node.attribute,context))
Exemplo n.º 7
0
def tag_help(node,context):
    """[help command] - Returns the documentation for command."""
    return command.get_command(get_var(node.attribute,context)).help(context.interface.prefix)
Exemplo n.º 8
0
def tag_google(node,context):
    """[google phrase] Fetches google data for a phrase. Sets the value of variables g_succes, g_url and g_content."""
    data = get_google_data(dynamic_core.get_var(node.attribute,context))
    for x in data.keys():
        context.vars["g_%s"%x] = data[x]
Exemplo n.º 9
0
def tag_weather_data(node,context):
    """[weather_data location] - Get data for the weather at a location. Returns nothing, but sets the values of [weather_success], [weather_info] and possibly [humidity], [celcius], [farenheight], and [conditions]."""
    data = get_wunderground_data(dynamic_core.get_var(node.attribute,context))
    for x in data:
        if not x in context.vars:
            context.vars[x]=data[x]
Exemplo n.º 10
0
def tag_weather_text(node,context):
    """[weather_text location] - Get a nice description of the weather in a location."""
    return get_wunderground_text(dynamic_core.get_var(node.attribute,context))