我正在创建这个 cron 作业来获取 twitter 提要并将其存储在数据存储中。我尝试了一切,但我的 cronjob 无法正常工作。我阅读了以下文章/教程和一些 stackoverflow 问题,但我无法解决这个问题。
https://developers.google.com/appengine/docs/python/config/cron
http://cloudartisan.com/posts/2010-06-02-scheduled-tasks-with-google-app-engine-python/
这是我的代码
这是 cron.ymal
cron:
- description : capture twitter feed
url : /twittertask
schedule: every 1 minutes
target: version-2
这是我完成这项工作所需的课程。
import webapp2
from google.appengine.ext import db
class Twitt(db.Model):
created_at = db.IntegerProperty(required = True)
id = db.StringProperty(required = True)
text = db.StringProperty(required = True)
class TwitterTask(webapp2.RequestHandler):
def get(self):
url = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=BeijingAir&count=10"
json_string = urllib2.urlopen(url).read()
data = json.loads(json_string)
for item in data:
created_at_item = item['created_at']
text_item = item['text']
id_item = item['id']
e = Twitt(id = created_at_item, text = text_item, id = id_item)
e.put()
self.response.out.write('Hello prueba!')
这是 app.ymal
application: cronjob
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: index.app
- url: /twittertask
script: twittertask.app
这是 index.py
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello, Check Admin')
app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
好吧,我找不到错误在哪里。我在我的开发服务器上进行了测试。我没有将它上传到谷歌应用引擎。