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


Python WebUtils.shortenGoogl方法代码示例

本文整理汇总了Python中Utils.WebUtils.shortenGoogl方法的典型用法代码示例。如果您正苦于以下问题:Python WebUtils.shortenGoogl方法的具体用法?Python WebUtils.shortenGoogl怎么用?Python WebUtils.shortenGoogl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Utils.WebUtils的用法示例。


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

示例1: execute

# 需要导入模块: from Utils import WebUtils [as 别名]
# 或者: from Utils.WebUtils import shortenGoogl [as 别名]
    def execute(self, message):
        """
        @type message: IRCMessage
        """
        wtfsimfd = "http://whatthefuckshouldimakefordinner.com/{}"

        options = {'meat': 'index.php', 'veg': 'veg.php', 'drink': 'drinks.php'}

        option = 'meat'
        if len(message.ParameterList) > 0:
            option = message.ParameterList[0]

        if option in options:
            webPage = WebUtils.fetchURL(wtfsimfd.format(options[option]))

            soup = BeautifulSoup(webPage.body)

            phrase = soup.find('dl').text
            item = soup.find('a')
            link = WebUtils.shortenGoogl(item['href'])

            return IRCResponse(ResponseType.Say,
                               u"{}... {} {}".format(phrase, item.text, link),
                               message.ReplyTo)

        else:
            error = u"'{}' is not a recognized dinner type, please choose one of {}"\
                .format(option, u'/'.join(options.keys()))
            return IRCResponse(ResponseType.Say, error, message.ReplyTo)
开发者ID:DotsTheHero,项目名称:PyMoronBot,代码行数:31,代码来源:Dinner.py

示例2: _stringifyTweet

# 需要导入模块: from Utils import WebUtils [as 别名]
# 或者: from Utils.WebUtils import shortenGoogl [as 别名]
    def _stringifyTweet(self, tweet):
        """
        turn a tweet object into a nice string for us to send to IRC
        @type tweet: dict[str, T/str]
        """
        retweet = None
        # get the original tweet if this is a retweet
        if 'retweeted_status' in tweet:
            retweet = tweet
            tweet = retweet['retweeted_status']

        tweetText = StringUtils.unescapeXHTML(tweet['text'])
        tweetText = re.sub('[\r\n]+', StringUtils.graySplitter, tweetText)
        for url in tweet['entities']['urls']:
            tweetText = tweetText.replace(url['url'], url['expanded_url'])

        timestamp = parser.parse(tweet['created_at'])
        timeString = timestamp.strftime('%A, %Y-%m-%d %H:%M:%S %Z')
        delta = datetime.datetime.utcnow() - timestamp.replace(tzinfo=None)
        deltaString = StringUtils.deltaTimeToString(delta)
        tweetText = u'{} (tweeted {}, {} ago)'.format(tweetText, timeString, deltaString)

        if retweet is None:
            user = tweet['user']['screen_name']
        else:
            user = retweet['user']['screen_name']
            tweetText = 'RT {}: {}'.format(tweet['user']['screen_name'], tweetText)
            
        link = u'https://twitter.com/{}/status/{}'.format(tweet['user']['screen_name'], tweet['id_str'])
        link = WebUtils.shortenGoogl(link)

        formatString = unicode(assembleFormattedText(A.normal[A.bold['@{0}>'], ' {1} {2}']))
        newTweet = formatString.format(user, tweetText, link)
        return newTweet
开发者ID:DotsTheHero,项目名称:PyMoronBot,代码行数:36,代码来源:Twitter.py

示例3: execute

# 需要导入模块: from Utils import WebUtils [as 别名]
# 或者: from Utils.WebUtils import shortenGoogl [as 别名]
 def execute(self, message):
     """
     @type message: IRCMessage
     """
     if len(message.ParameterList) == 0:
         return IRCResponse(ResponseType.Say, "You didn't give a URL to shorten!", message.ReplyTo)
     
     url = WebUtils.shortenGoogl(message.Parameters)
     
     return IRCResponse(ResponseType.Say, url, message.ReplyTo)
开发者ID:DotsTheHero,项目名称:PyMoronBot,代码行数:12,代码来源:Googl.py

示例4: execute

# 需要导入模块: from Utils import WebUtils [as 别名]
# 或者: from Utils.WebUtils import shortenGoogl [as 别名]
    def execute(self, message):
        """
        @type message: IRCMessage
        """
        responses = []
        for feedName, feedDeets in DataStore.LRRChecker.iteritems():
            if feedDeets['lastCheck'] > datetime.datetime.utcnow() - datetime.timedelta(minutes=10):
                continue
            
            DataStore.LRRChecker[feedName]['lastCheck'] = datetime.datetime.utcnow()
            
            feedPage = WebUtils.fetchURL(feedDeets['url'])
            
            if feedPage is None:
                #TODO: log an error here that the feed likely no longer exists!
                continue
            
            root = ET.fromstring(feedPage.body)
            item = root.find('channel/item')
            
            if item is None:
                #TODO: log an error here that the feed likely no longer exists!
                continue

            title = DataStore.LRRChecker[feedName]['lastTitle'] = item.find('title').text
            link = DataStore.LRRChecker[feedName]['lastLink'] = WebUtils.shortenGoogl(item.find('link').text)
            newestDate = dparser.parse(item.find('pubDate').text, fuzzy=True, ignoretz=True)
            
            if newestDate > feedDeets['lastUpdate']:
                DataStore.LRRChecker[feedName]['lastUpdate'] = newestDate
                
                if feedDeets['suppress']:
                    DataStore.LRRChecker[feedName]['suppress'] = False
                else:
                    response = 'New {0}! Title: {1} | {2}'.format(feedName, title, link)
                    responses.append(IRCResponse(ResponseType.Say, response, '#desertbus'))
            
        return responses
开发者ID:DotsTheHero,项目名称:PyMoronBot,代码行数:40,代码来源:LRRChecker.py


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