当前位置: 首页>>代码示例>>Python>>正文


Python ircutils.underline函数代码示例

本文整理汇总了Python中supybot.ircutils.underline函数的典型用法代码示例。如果您正苦于以下问题:Python underline函数的具体用法?Python underline怎么用?Python underline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了underline函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _printWikiPage

 def _printWikiPage(self, values):
     action = values.get('action')
     if action is not None:
         if action == 'created':
             action = 'created by %s' % underline(values['author'])
         elif action == 'changed':
             action = 'changed by %s' % underline(values['author'])
         action = ' (%s)' % action
     yield format('%s%s %u',
         bold(values['name']),
         action or '',
         values['url']
     )
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:13,代码来源:plugin.py

示例2: _finalgame

    def _finalgame(self, gamedate, gameid):
        """Grabs the boxscore json and prints a final statline."""

        url = b64decode('aHR0cDovL2RhdGEubmJhLmNvbS9qc29uL2Ntcy9ub3NlYXNvbi9nYW1lLw==') + '%s/%s/boxscore.json' % (str(gamedate), str(gameid))
        html = self._httpget(url)
        if not html:
            self.log.error("ERROR: Could not _finalgame.")
            return None
        # process json. throw this thing in a try/except block.
        try:
            jsonf = json.loads(html.decode('utf-8'))
            game = jsonf['sports_content']['game']
            if len(game) == 0:
                self.log.error("_finalgame :: I found no games in the json data.")
                return None

            # output dict. we preset DD/TD for later.
            gamestats = {'Double-double':[], 'Triple-double':[]}
            # iterate over the home/visitor.
            for var in ['visitor', 'home']:
                team = game[var]['abbreviation']
                fgp = game[var]['stats']['field_goals_percentage']
                tpp = game[var]['stats']['three_pointers_percentage']
                ftp = game[var]['stats']['free_throws_percentage']
                to = game[var]['stats']['turnovers']
                rb = (int(game[var]['stats']['rebounds_offensive'])+int(game[var]['stats']['rebounds_defensive']))  # total rb.
                ptsl = sorted(game[var]['players']['player'], key=lambda t: int(t['points']), reverse=True)[0]  # sort by points
                astl = sorted(game[var]['players']['player'], key=lambda t: int(t['assists']), reverse=True)[0]  # sort by assists. below we sort by adding rebounds.
                rbll = sorted(game[var]['players']['player'], key=lambda x: (int(x['rebounds_offensive']) + int(x['rebounds_defensive'])), reverse=True)[0]
                # inject into our gamestats dict with the text.
                gamestats[team] = "{0}: {1} {2}: {3} {4}: {5} {6}: {7} {8}: {9}  {10} :: {11} {12} {13} {14} {15} {16} {17} {18} {19}".format(\
                      ircutils.bold("FG%"), fgp,
                      ircutils.bold("FT%"), ftp,
                      ircutils.bold("3PT%"), tpp,
                      ircutils.bold("TO"), to,
                      ircutils.bold("RB"), rb,
                      ircutils.bold(ircutils.underline("LEADERS")),
                      ircutils.bold("PTS"), ptsl['last_name'].encode('utf-8'), ptsl['points'],
                      ircutils.bold("AST"), astl['last_name'].encode('utf-8'), astl['assists'],
                      ircutils.bold("RB"), rbll['last_name'].encode('utf-8'), (int(rbll['rebounds_offensive'])+int(rbll['rebounds_defensive'])))
                # look for DD/TD
                for x in game[var]['players']['player']:  # iterate over.
                    tmp = {}  # we make a dict with the key as the stat for later.
                    tmp['rb'] = int(x['rebounds_offensive']) + int(x['rebounds_defensive'])
                    tmp['blocks'] = int(x['blocks'])
                    tmp['a'] = int(x['assists'])
                    tmp['p'] = int(x['points'])
                    tmp['s'] = int(x['steals'])
                    # we only inject into matching the category and stat if 10 or over.
                    matching = [str(z.upper()) + ": " + str(p) for (z, p) in tmp.items() if p >= 10]
                    if len(matching) == 2:  # dd. inject into gamestats in the right category.
                        gamestats['Double-double'].append("{0}({1}) :: {2}".format(x['last_name'].encode('utf-8'), team, " | ".join(matching)))
                    if len(matching) > 2:  # likewise with td.
                        gamestats['Triple-double'].append("{0}({1}) :: {2}".format(x['last_name'].encode('utf-8'), team, " | ".join(matching)))

            # return the dict.
            return gamestats
        except Exception, e:
            self.log.error("_finalgame: ERROR on {0} :: {1}".format(url, e))
            return None
开发者ID:reticulatingspline,项目名称:NBA,代码行数:60,代码来源:plugin.py

示例3: present_listing_first

def present_listing_first(res, original_link=False, color_score=False):
	try:
		d = res.get("data", {}).get("children", [{}])[0].get("data",{})
		if d:
			if not original_link:
				d["url"] = "http://www.reddit.com/r/%(subreddit)s/comments/%(id)s/" % d
            
			if color_score:
				score_part = "(%s|%s)[%s]" % (ircutils.bold(ircutils.mircColor("%(ups)s", "orange")),
                                              ircutils.bold(ircutils.mircColor("%(downs)s", "12")),
                                              ircutils.bold(ircutils.mircColor("%(num_comments)s", "dark grey")))
			else:
				score_part = "(%(score)s)"
			title_part = "%(title)s"
			url_part = ircutils.underline("%(url)s")
			nsfw_part = "NSFW"*d['over_18'] or ''
			nsfw_part =ircutils.bold(ircutils.mircColor(nsfw_part, 'red'))
			template = "%s %s %s %s" % (nsfw_part, score_part, title_part, url_part)
			template = (template % d)
			template = template.replace('\n', ' ')
			template = template.replace('&','&')
		
			if d["created_utc"] < time.time() - 2678400:
				return False
			return template
			
    
	except IndexError:
		return None
开发者ID:AwwCookies,项目名称:peacekeeper,代码行数:29,代码来源:plugin.py

示例4: testStripFormatting

 def testStripFormatting(self):
     self.assertEqual(ircutils.stripFormatting(ircutils.bold("foo")), "foo")
     self.assertEqual(ircutils.stripFormatting(ircutils.italic("foo")), "foo")
     self.assertEqual(ircutils.stripFormatting(ircutils.reverse("foo")), "foo")
     self.assertEqual(ircutils.stripFormatting(ircutils.underline("foo")), "foo")
     self.assertEqual(ircutils.stripFormatting("\x02bold\x0302,04foo\x03" "bar\x0f"), "boldfoobar")
     s = ircutils.mircColor("[", "blue") + ircutils.bold("09:21")
     self.assertEqual(ircutils.stripFormatting(s), "[09:21")
开发者ID:ProgVal,项目名称:Limnoria,代码行数:8,代码来源:test_ircutils.py

示例5: cfbschedule

    def cfbschedule(self, irc, msg, args, optteam):
        """[team]
        Display the schedule/results for team.
        """
        
        lookupteam = self._lookupTeam(optteam)
        
        if lookupteam == "0":
            irc.reply("I could not find a schedule for: %s" % optteam)
            return
        
        url = 'http://www.cbssports.com/collegefootball/teams/schedule/%s/' % lookupteam

        try:
            req = urllib2.Request(url)
            html = (urllib2.urlopen(req)).read()
        except:
            irc.reply("Failed to open: %s" % url)
            return
            
        html = html.replace('&amp;','&').replace(';','')
    
        soup = BeautifulSoup(html)
        
        if soup.find('table', attrs={'class':'data stacked'}).find('tr', attrs={'class':'title'}).find('td'):
            title = soup.find('table', attrs={'class':'data stacked'}).find('tr', attrs={'class':'title'}).find('td')
        else:
            irc.reply("Something broke with schedules. Did formatting change?")
            return

        div = soup.find('div', attrs={'id':'layoutTeamsPage'}) # must use this div first since there is an identical table.
        table = div.find('table', attrs={'class':'data', 'width':'100%'})
        rows = table.findAll('tr', attrs={'class':re.compile('^row[1|2]')})

        append_list = []
        
        for row in rows:
            date = row.find('td')
            team = date.findNext('td').find('a')
            time = team.findNext('td')
            
            if team.text.startswith('@'): # underline home
                team = team.text
            else:
                team = ircutils.underline(team.text)
        
            if time.find('span'): # span has score time. empty otherwise.
                time = time.find('span').string
                append_list.append(date.text + " - " + ircutils.bold(team) + " (" + time + ")")
            else:
                time = time.string
                append_list.append(date.text + " - " + ircutils.bold(team))

        descstring = string.join([item for item in append_list], " | ")
        output = "{0} for {1} :: {2}".format(title.text, ircutils.bold(optteam.title()), descstring)
        
        irc.reply(output)
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:57,代码来源:plugin.py

示例6: _printTicket

 def _printTicket(self, values):
     action = values.get('action')
     if action is not None:
         if action == 'created':
             action = 'created by %s' % underline(values['reporter'])
         elif action == 'changed':
             action = 'changed by %s' % underline(values['author'])
         comment = values['comment']
         if comment:
             comment = ', ' + comment
         action = ' (%s%s)' % (action, comment)
     yield format('%s #%s: %s%s',
         bold('Ticket'),
         values['id'],
         values['summary'],
         action or ''
     )
     yield '<%s>' % values['url']
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:18,代码来源:plugin.py

示例7: _printChangeset

 def _printChangeset(self, values):
     yield format('%s [%s] by %s in %s (%n): %s',
         bold('Changeset'),
         values['rev'],
         underline(values['author']),
         values['path'],
         (values['file_count'], 'file'),
         ellipsisify(values['message'].strip(), 130)
     )
     yield '<%s>' % values['url']
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:10,代码来源:plugin.py

示例8: _outputTweet

 def _outputTweet(self, irc, msg, nick, name, text, time, tweetid):
     ret = ircutils.underline(ircutils.bold("@" + nick))
     hideName = self.registryValue('hideRealName', msg.args[0])
     if not hideName:
         ret += " ({0})".format(name)
     ret += ": {0} ({1})".format(text, ircutils.bold(time))
     if self.registryValue('addShortUrl', msg.args[0]):
         url = self._createShortUrl(nick, tweetid)
         if (url):
             ret += " {0}".format(url)
     irc.reply(ret)
开发者ID:crazedpsyc,项目名称:Supybot-plugins,代码行数:11,代码来源:plugin.py

示例9: port

    def port(self, irc, msg, args, port):
        """<port number>

        Looks up <port number> in Wikipedia's list of ports at
        https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers.
        """
        if port > 65535:
            irc.error('Port numbers cannot be greater than 65535.', Raise=True)
        if BeautifulSoup is None:
            irc.error("Beautiful Soup 4 is required for this plugin: get it"
                      " at http://www.crummy.com/software/BeautifulSoup/bs4/"
                      "doc/#installing-beautiful-soup", Raise=True)
        url = "https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers"
        fd = utils.web.getUrlFd(url)
        soup = BeautifulSoup(fd)
        if port >= 49152:
            results = ['The range 49152–65535 (2^15+2^14 to 2^16−1)—above the '
                       'registered ports—contains dynamic or private ports that '
                       'cannot be registered with IANA. This range is used for '
                       'custom or temporary purposes and for automatic '
                       'allocation of ephemeral ports.']
        else:
            results = []
            for tr in soup.find_all('tr'):
                tds = tr.find_all('td')
                if not tds:
                    continue
                portnum = tds[0].text
                if '–' in portnum:
                    startport, endport = map(int, portnum.split('–'))
                    p = range(startport, endport+1)
                else:
                    try:
                        p = [int(portnum)]
                    except ValueError:
                        continue
                if port in p:
                    text = tds[3].text
                    # Remove inline citations (text[1][2][3]), citation needed tags, etc.
                    text = re.sub('\[.*?]', '', text)

                    # List the port notes (tags such as "Official", "TCP", "UDP", etc.)
                    # This is every <td> tag except the 4th one, which is the description parsed
                    # above.
                    notes = [t.text.strip() for t in tds[:3]+tds[4:]]
                    notes = '; '.join(filter(None, notes))

                    # Remove \n, etc. in fields to prevent output corruption.
                    s = utils.str.normalizeWhitespace('%s [%s]' % (ircutils.bold(text), notes))
                    results.append(s)
        if results:
            irc.reply(format('%s: %L', ircutils.bold(ircutils.underline(port)), results))
        else:
            irc.error(_('No results found.'))
开发者ID:Hasimir,项目名称:glolol-supy-plugins,代码行数:54,代码来源:plugin.py

示例10: testStripFormatting

 def testStripFormatting(self):
     self.assertEqual(ircutils.stripFormatting(ircutils.bold('foo')), 'foo')
     self.assertEqual(ircutils.stripFormatting(ircutils.reverse('foo')),
                      'foo')
     self.assertEqual(ircutils.stripFormatting(ircutils.underline('foo')),
                      'foo')
     self.assertEqual(ircutils.stripFormatting('\x02bold\x0302,04foo\x03'
                                               'bar\x0f'),
                      'boldfoobar')
     s = ircutils.mircColor('[', 'blue') + ircutils.bold('09:21')
     self.assertEqual(ircutils.stripFormatting(s), '[09:21')
开发者ID:krattai,项目名称:AEBL,代码行数:11,代码来源:test_ircutils.py

示例11: wootshirt

 def wootshirt(self, irc, msg, args):	
     """ Display daily woot.com deal."""
 
     url = "http://shirt.woot.com/salerss.aspx"
 
     dom = xml.dom.minidom.parse(urllib2.urlopen(url))
 
     product = dom.getElementsByTagName("woot:product")[0].childNodes[0].data
     price = dom.getElementsByTagName("woot:price")[0].childNodes[0].data
     purchaseurl = dom.getElementsByTagName("woot:purchaseurl")[0].childNodes[0].data
     soldout = dom.getElementsByTagName("woot:soldout")[0].childNodes[0].data # false
     shipping = dom.getElementsByTagName("woot:shipping")[0].childNodes[0].data
 
     if soldout == 'false':
         output = ircutils.mircColor("IN STOCK ", "green")
     else:
         output = ircutils.mircColor("SOLDOUT ", "red")
 
     output += ircutils.underline(ircutils.bold("ITEM:")) + " " + product + " "
     output += ircutils.underline(ircutils.bold("PRICE:")) + " " + price + " (Shipping:" + shipping + ") "
     output += ircutils.underline(ircutils.bold("URL:")) + " " + self._shortenUrl(purchaseurl) + " "
 
     irc.reply(output, prefixNick=True)
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:23,代码来源:plugin.py

示例12: tennis

    def tennis(self, irc, msg, args, optmatch):
        """<mens|womens|mensdoubles|womensdoubles>
        Display current Tennis scores. Defaults to Men's Singles.
        """
        
        if optmatch:
            if optmatch == "womens":
                matchType = "2"
            elif optmatch == "mensdoubles":
                matchType = "3"
            elif optmatch == "womensdoubles":
                matchType = "4"
            else:
                matchType = "1"
        else:
            matchType = "1"
        
        url = 'general/tennis/dailyresults?matchType=%s' % matchType
        
        html = self._fetch(url)
        
        if html == 'None':
            irc.reply("Cannot fetch Tennis scores.")
            return
        
        soup = BeautifulSoup(html)
        tournament = soup.find('div', attrs={'class': 'sec row', 'style': 'white-space: nowrap;'})
        tournRound = soup.findAll('div', attrs={'class': 'ind sub bold'})[1] # there are two here, only display the 2nd, which is status.
        divs = soup.findAll('div', attrs={'class':re.compile('^ind$|^ind alt$')}) 

        append_list = []

        for div in divs:
            if "a href" not in div.renderContents(): # only way to get around this as the divs are not in a container.
                status = div.find('b') # find bold, which is status.
                if status:
                    status.extract() # extract so we may bold.
                
                div = div.renderContents().strip().replace('<br />',' ').replace('  ',' ')
                div = div.replace('v.',ircutils.mircColor('v.','green')).replace('d.',ircutils.mircColor('d.','red')) # colors.
                append_list.append(str(ircutils.underline(status.getText()) + " " + div.strip()))
            
        if len(append_list) > 0: # Sanity check.
            if tournament and tournRound:
                irc.reply(ircutils.mircColor(tournament.getText(), 'red') + " - " + ircutils.bold(tournRound.getText()))
                
            irc.reply(" | ".join(item for item in append_list))
        else:
            irc.reply("I did not find any active tennis matches.") 
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:49,代码来源:plugin.py

示例13: present_listing_first

def present_listing_first(res, original_link=False, color_score=False):
    d = res.get("data", {}).get("children", [{}])[0].get("data",{})
    if d:
        if not original_link:
            d["url"] = "http://www.reddit.com/r/%(subreddit)s/comments/%(id)s/" % d
            
        if color_score:
            score_part = "(%s/%s)[%s]" % (ircutils.mircColor("%(ups)s", "orange"),
                                          ircutils.mircColor("%(downs)s", "light blue"),
                                          ircutils.mircColor("%(num_comments)s", "dark grey"))
        else:
            score_part = "(%(score)s)"
        title_part = ircutils.bold("%(title)s")
        url_part = ircutils.underline("%(url)s")
        template = "%s \"%s\" %s" % (score_part, title_part, url_part)
        return (template % d)
开发者ID:PoohBearIRC,项目名称:supybot-reddit,代码行数:16,代码来源:plugin.py

示例14: _formatLine

 def _formatLine(self, line, channel, type):
     """Implements the 'format' configuration options."""
     format = self.registryValue('format.%s' % type, channel)
     already_colored = False
     for item in format:
         if item == 'bold':
             line = ircutils.bold(line)
         elif item == 'reverse':
             line = ircutils.reverse(line)
         elif item == 'underlined':
             line = ircutils.underline(line)
         elif already_colored:
             line = ircutils.mircColor(line, bg=item)
         elif item != '':
             line = ircutils.mircColor(line, fg=item)
     return line
开发者ID:CloudStack-extras,项目名称:cso-infrastructure,代码行数:16,代码来源:plugin.py

示例15: cfbweeklyleaders

    def cfbweeklyleaders(self, irc, msg, args):
        """
        Display CFB weekly leaders.
        """
        
        url = 'http://espn.go.com/college-football/weekly'

        try:
            req = urllib2.Request(url)
            html = (urllib2.urlopen(req)).read()
        except:
            irc.reply("Failed to open: %s" % url)
            return
    
        html = html.replace('tr class="evenrow', 'tr class="oddrow')

        soup = BeautifulSoup(html)
        title = soup.find('h1', attrs={'class':'h2'}) 
        tables = soup.findAll('table', attrs={'class':'tablehead'}) 

        new_data = collections.defaultdict(list)

        for table in tables:
            rows = table.findAll('tr', attrs={'class':re.compile('^oddrow.*')})[0:3] # top 3 only. List can be long. 
            for j,row in enumerate(rows): 
                stat = row.findPrevious('tr', attrs={'class':'stathead'})
                colhead = row.findPrevious('tr', attrs={'class':'colhead'}).findAll('td')
                statnames = row.findAll('td')

                del statnames[3], colhead[3] # game is always 4th. delete this. 
        
                for i,statname in enumerate(statnames):            
                    appendString = str(ircutils.bold(colhead[i].text)) + ": " + str(statname.text) # prep string to add into the list.
            
                    if i == len(statnames)-1 and not j == len(rows)-1: # last in each.
                        new_data[str(stat.getText())].append(appendString + " |")  
                    else:
                        new_data[str(stat.getText())].append(appendString)
                
        if title:
            irc.reply(ircutils.mircColor(title.getText(), 'blue'))
        
        for i,j in new_data.iteritems():
            output = "{0} :: {1}".format(ircutils.underline(i), string.join([item for item in j], " "))
            irc.reply(output)
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:45,代码来源:plugin.py


注:本文中的supybot.ircutils.underline函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。