在Meteor中调用Python脚本

ldh*_*ldh 5 python mongodb meteor

让我的meteor应用程序调用python与流星服务器端代码驻留在同一台机器上的脚本的最佳方法是什么?我想做的就是让meteor将一个字符串传递给python中的一个函数,让python将一个字符串返回给meteor.

我想我可以有python监视器mongodb并提取值并在计算后将它们写回mongodb,但让meteor直接调用python中的函数似乎更清晰.

我是DDP的新手,并且无法使用python-meteor(https://github.com/hharnisc/python-meteor).

ZeroRPC(http://zerorpc.dotcloud.com/)是一个很好的方法吗?

谢谢.

emh*_*emh 7

好问题.

我已经看过使用DDP和ZeroRPC,甚至让Python直接写入Mongo.

对我来说,让Meteor和Python谈话的最简单方法是将python脚本设置为烧瓶应用程序,然后将API添加到烧瓶应用程序中,让Meteor通过API与Python对话.

为了使这个设置工作我使用:

要测试它,您可以构建一些基本的东西(python脚本将文本转换为大写):

from flask import Flask
from flask.ext import restful

app = Flask(__name__)
api = restful.Api(app)

class ParseText(restful.Resource):
    def get(self, text):
        output = text.upper()
        return output

api.add_resource(ParseText, '/<string:text>')

if __name__ == '__main__':
    app.run(debug=True) # debug=True is for testing to see if calls are working.
Run Code Online (Sandbox Code Playgroud)

然后在Meteor中HTTP.get用来测试调用API.

如果您在本地运行所有内容,那么来自Meteor的调用可能看起来像: Meteor.http.get("http://127.0.0.1:5000/test");