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


Python Translator.entofr方法代码示例

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


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

示例1: BotnetJabberClient

# 需要导入模块: from translate import Translator [as 别名]
# 或者: from translate.Translator import entofr [as 别名]
class BotnetJabberClient(GTalkBot):

    BOT_USER = '[email protected]'
    BOT_PASS = 'pycon123'

    def __init__(self):
        self.eliza = eliza()
        super(BotnetJabberClient,self).__init__(self.BOT_USER, self.BOT_PASS)
        self.geoPlanet = YahooGeoPlanetSearch()
        self.yahooWeather = YahooWeatherSearch()
        self.pyconIreland = PyconIreland()
        self.translator = Translator()

    @botcommand
    def weather(self, mess, args):
        """Returns the forecasts for any place. Usage: weather [City Name]"""
        try:
            woeid = self.geoPlanet.place_search(args).woeid()
            result = self.format_weather_result(self.yahooWeather.forecast(woeid))
            return result.encode("utf-8")
        except InvalidSearchError:
            return "Invalid Search, plz try again"
        except Exception:
            return "Unknow error... sorry about that"

    @botcommand
    def currency(self, mess, args):
        """Returns updated information about Dollar currency"""
        return finance.exchange_rate()
        
        
    @botcommand
    def talk(self, mess, args):
        "Retrieves information about talks at Pycon Ireland 2010. Search for the authors name or the talks name"
        return self.pyconIreland.find_talk(args)
    
    @botcommand
    def speaker(self, mess, args):
        """Returns Information about any of the speakers at Pycon Ireland 2010"""
        return self.pyconIreland.find_speaker(args)
        
    def unknown_command( self, mess, cmd, args):
        """Putting some Mojo here to make the bot answer as Eliza when wrong command is given""" 
        return self.eliza.respond(mess.getBody())
        
    
    def format_weather_result(self, result):
        model_header = "{0}\n {1} C - {2} \n Forecasts\n"
        model_forecasts = "{0} -> {1} with max {2} C | min {3} C\n"  
        
        forecast_result = model_header.format(result['title'], result['current_temp'], result['current_condition'])
        for forecast in result['forecasts']:
            forecast_result += model_forecasts.format(forecast['date'], forecast['condition'], forecast['high'], forecast['low'])
        
        return forecast_result

    @botcommand
    def entofr(self, mess, args):
        """Returns the French translation of an English word. Usage: entofr [Word in English]"""
        return self.translator.entofr(args)

    @botcommand
    def frtoen(self, mess, args):
        """Returns the English translation of a French word. Usage: frtoen [Word in French]"""
        return self.translator.frtoen(args)
开发者ID:jpichon,项目名称:botnet,代码行数:67,代码来源:botnet.py


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