2013-08-05 21 views
-1

作为一个研究项目的一部分,我已经消耗从Twitter微博为本地托管的MongoDB数据库的脚本:如何将我的脚本变成远程托管的应用程序?

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=['snowden']) 

为了提高正常运行时间,我希望做两件事情:1)远程运行此脚本,以及ii)将消费的推文存储在云中。然而,对于编程的所有事物来说,这是一个全新的概念,我失去了为了实现自己的目标应该做些什么。我的下一步是什么?正常运行时间的“最小阻力路径”是什么?

回答

2

Heroku是一个支持Python和MongoDB的云平台,我建议您使用它。 This link提供了有关如何执行此操作的工作参考。

这里有另一对夫妇的链接来帮助你:

1)Python database WITHOUT using Django (for Heroku)

2)How can I use the mongolab add-on to Heroku from python?

希望这有助于! OK。

+0

OK。我是否需要为我的脚本创建一个Github仓库,然后将其部署到Heroku?到目前为止,我一直在我的(mac)计算机上从终端直接运行我的脚本。 – user2161725

+0

不需要... Heroku内置了Git支持。查看此入门教程:https://devcenter.heroku.com/articles/python – 2013-08-05 17:21:21

+0

感谢您访问Heroku入门教程的链接。按照教程中的步骤,我已经成功设置了一个干净的烧瓶环境,编写了一个helloworld.py应用程序并将其部署到Heroku。到现在为止还挺好。但是,我不知道如何修改我的源代码(请参阅原始问题),以便它可以作为Flask应用程序运行。有什么想法吗? – user2161725