【问题标题】:How do I turn my script into a remotely hosted app? [closed]如何将我的脚本变成远程托管的应用程序? [关闭]
【发布时间】:2013-08-05 09:09:48
【问题描述】:

作为研究项目的一部分,我有一个脚本,可以将来自 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'])

为了提高正常运行时间,我想做两件事:i) 远程运行此脚本,以及 ii) 将使用的推文存储在云中。但是,对于所有编程事物都是全新的,我不知道应该做什么来实现我的目标。我的下一步是什么?正常运行时间的“阻力最小路径”是什么?

【问题讨论】:

    标签: python mongodb twitter uptime


    【解决方案1】:

    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?

    希望这会有所帮助!

    【讨论】:

    • 好的。我是否需要为我的脚本创建一个 Github 存储库,然后将其部署到 Heroku?到目前为止,我一直在我的(mac)计算机上直接从终端运行我的脚本。
    • 不需要...Heroku 内置了 Git 支持。查看此入门教程:devcenter.heroku.com/articles/python
    • 感谢您提供 Heroku 入门教程的链接。按照教程中的步骤,我已经成功设置了一个干净的烧瓶环境,编写了一个 helloworld.py 应用程序并将这个应用程序部署到 Heroku。到现在为止还挺好。但是,我不知道如何修改我的源代码(请参阅原始问题),以便它将作为 Flask 应用程序运行。有什么想法吗?
    猜你喜欢
    • 2023-03-28
    • 2012-11-21
    • 1970-01-01
    • 2013-06-05
    • 2013-02-28
    • 2010-09-23
    • 1970-01-01
    • 2017-08-25
    • 2012-03-27
    相关资源
    最近更新 更多