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


Python WebUtils.sendToServer方法代码示例

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


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

示例1: execute

# 需要导入模块: from Utils import WebUtils [as 别名]
# 或者: from Utils.WebUtils import sendToServer [as 别名]
    def execute(self, message):
        """
        @type message: IRCMessage
        """
        if message.User.Name != message.ReplyTo:
            return IRCResponse(ResponseType.Say, "GPS Lookup must be done via PM", message.ReplyTo)
        
        if len(message.ParameterList) > 0:
            if self.api_key is None:
                return IRCResponse(ResponseType.Say, "[Bing Maps API key not found]", message.ReplyTo)

            url = "http://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}".format(urllib.quote_plus(message.Parameters), self.api_key)

            j = WebUtils.sendToServer(url)
            result = json.loads(j)

            if result['resourceSets'][0]['estimatedTotal'] == 0:
                print result
                return IRCResponse(ResponseType.Say,
                                   "Couldn't find GPS coords for '{0}', sorry!".format(message.Parameters),
                                   message.ReplyTo)

            coords = result['resourceSets'][0]['resources'][0]['point']['coordinates']

            return IRCResponse(ResponseType.Say,
                               "GPS coords for '{0}' are: {1},{2}".format(message.Parameters, coords[0], coords[1]),
                               message.ReplyTo)

        else:
            return IRCResponse(ResponseType.Say,
                               "You didn't give an address to look up",
                               message.ReplyTo)
开发者ID:HubbeKing,项目名称:PyMoronBot,代码行数:34,代码来源:GPSLookup.py

示例2: execute

# 需要导入模块: from Utils import WebUtils [as 别名]
# 或者: from Utils.WebUtils import sendToServer [as 别名]
 def execute(self, message):
     """
     @type message: IRCMessage
     """
     if len(message.ParameterList) == 0:
         return IRCResponse(ResponseType.Say,
                            "You didn't give an expression to calculate! {0}".format(self.help),
                            message.ReplyTo)
     
     query = urllib.quote(message.Parameters.encode('utf8'))
     j = WebUtils.sendToServer('http://www.google.com/ig/calculator?hl=en&q=' + query)
     j = re.sub(r"{\s*'?(\w)", r'{"\1', j)
     j = re.sub(r",\s*'?(\w)", r',"\1', j)
     j = re.sub(r"(\w)'?\s*:", r'\1":', j)
     j = re.sub(r":\s*'(\w)'\s*([,}])", r':"\1"\2', j)
     j = self.htmlParser.unescape(j)
     j = j.replace('\xa0', ',')
     j = j.replace('\\x3c', '<')
     j = j.replace('\\x3e', '>')
     j = j.replace('<sup>', '^(')
     j = j.replace('</sup>', ')')
     print j
     result = json.loads(j)
     
     if len(result['rhs']) > 0:
         return IRCResponse(ResponseType.Say,
                            "{1}'s Result: {0}".format(result['rhs'], message.User.Name),
                            message.ReplyTo)
     if len(result['error']) > 0:
         return IRCResponse(ResponseType.Say,
                            'Calculation Error or Unsupported Operations',
                            message.ReplyTo)
开发者ID:DotsTheHero,项目名称:PyMoronBot,代码行数:34,代码来源:Calculate.py

示例3: execute

# 需要导入模块: from Utils import WebUtils [as 别名]
# 或者: from Utils.WebUtils import sendToServer [as 别名]
 def execute(self, message):
     """
     @type message: IRCMessage
     """
     if len(message.ParameterList) == 0:
         return IRCResponse(ResponseType.Say, 'Define what?', message.ReplyTo)
     
     query = urllib.quote(message.Parameters.encode('utf8'))
     url = 'http://www.google.com/dictionary/json?callback=a&sl=en&tl=en&q={0}'.format(query)
     j = WebUtils.sendToServer(url)
     j = j[2:]
     j = j[:-10]
     j = j.decode('string_escape')
     j = re.sub(r'</?[^>]+?>', '', j)
     defs = json.loads(j)
     
     numDefs = 0
     defsToDisp = 3
     responses = [IRCResponse(ResponseType.Say, 'Definitions for {0}:'.format(message.Parameters), message.ReplyTo)]
     defToDispIf = None
     for wordType in defs['primaries']:
         for definition in wordType['entries']:
             if definition['type'] == 'meaning':
                 numDefs += 1
                 if numDefs <= defsToDisp:
                     responses.append(IRCResponse(ResponseType.Say, '{0}. {1}'.format(numDefs, definition['terms'][0]['text']), message.ReplyTo))
                 if numDefs == defsToDisp+1:
                     defToDispIf = IRCResponse(ResponseType.Say, '{0}. {1}'.format(numDefs, definition['terms'][0]['text']), message.ReplyTo)
     if numDefs > defsToDisp+1:
         responses.append(IRCResponse(ResponseType.Say, 'And {1} more here: www.google.com/#tbs=dfn:1&q={0}'.format(query, numDefs-defsToDisp), message.ReplyTo))
     elif numDefs == defsToDisp+1:
         responses.append(defToDispIf)
                 
     if numDefs == 0:
         return IRCResponse(ResponseType.Say, 'No definitions found for {0}'.format(message.Parameters), message.ReplyTo)
     
     return responses
开发者ID:DotsTheHero,项目名称:PyMoronBot,代码行数:39,代码来源:Define.py


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