【发布时间】:2013-08-07 10:37:10
【问题描述】:
我有一个用 Python 编写的脚本,可以让我将来自终端的推文消费到本地托管的 mongodb 数据库中。为了提高正常运行时间,我想在 Heroku 上远程托管这个脚本,并将消费的推文拍摄到由 MongoHQ 托管的数据库中。因为我想在不使用 Django 的情况下执行此操作,所以我使用 Flask 框架将应用程序部署到 Heroku(在此处描述:https://devcenter.heroku.com/articles/python)。
当我使用此设置运行一个简单的“hello world”应用程序时,一切都很好。但是,当我尝试运行我的推文消费应用程序时,它会立即崩溃。如何将我的应用程序更改为可以与 Flask/Heroku/MongoHQ 设置一起使用?源代码为:
import json
import pymongo
import tweepy
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
class CustomStreamListener(tweepy.StreamListener):
def __init__(self, api):
self.api = api
super(tweepy.StreamListener, self).__init__()
self.db = pymongo.MongoClient().test
def on_data(self, tweet):
self.db.tweets.insert(json.loads(tweet))
def on_error(self, status_code):
return True # Don't kill the stream
def on_timeout(self):
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener(api))
sapi.filter(track=['rooney'])
我对编程完全陌生,所以我想这个问题的解决方案可能很简单。但是,我被困住了,真的可以使用一些帮助来取得进步。
【问题讨论】:
-
我的 heroku 日志是:State changed from started to crashed 2013-08-06T10:07:44.409065+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed在启动后 60 秒内绑定到 $PORT 2013-08-06T10:07:44.409351+00:00 heroku[web.1]: 使用 SIGKILL 停止进程
标签: python heroku flask tweepy mongohq