Main.js
Parse.Cloud.job("grabPrices", function(request, status) {
// Set up to modify user data
Parse.Cloud.httpRequest({
method: 'POST',
url: 'http://xxx.parseapp.com/xxx.py',
success: function(httpResponse) {
console.log(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
})
});
Main.js是我要运行的Parse Cloud Job,它基本上访问并运行python脚本。这可能吗?如果是这样,我应该对代码进行哪些更改?
我通过使用Heroku解决了我的问题。
我的代码类似于@AlexCoren的答案,如下所示:
Parse.Cloud.job("grabPrices", function(request, status) {
// Set up to modify user data
Parse.Cloud.httpRequest({
url: 'https://xxx.herokuapp.com/',
success: function(httpResponse) {
console.log(httpResponse.text);
status.success("Pricelist grabbed successfully!");
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
status.success("Oops.... something went wrong.");
}
})
});
对于heroku,我只是略微修改了views.py
文件(我只是遵循了教程“ python入门”,下载了示例项目并修改了\python-getting-started\hello\views.py
文件):
from django.shortcuts import render
from django.http import HttpResponse
import urllib2
import urllib
#import requests
import json, httplib
import time
from datetime import datetime
from .models import Greeting
# Create your views here.
def index(request):
# I put my python code here so it will run at the url `https://xxx.herokuapp.com/'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句