How do I run my Flask app remotely using MongoHQ and Heroku (Python) -
i have script written in python lets me consume tweets terminal locally hosted mongodb database. improve uptime, host script remotely on heroku , shoot consumed tweets database hosted mongohq. without using django, use flask framework deploy app heroku (described here: https://devcenter.heroku.com/articles/python).
when run simple "hello world" app using setup, fine. however, when try run tweet consuming app, crashes. how can change app work flask/heroku/mongohq setup? source code is:
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 stream def on_timeout(self): return true # don't kill stream sapi = tweepy.streaming.stream(auth, customstreamlistener(api)) sapi.filter(track=['rooney'])
i new programming imagine solution problem might quite straight forward. however, stuck , use progress.
it's hard debug without more information, first guess don't have dependancies installed.
heroku gives clean python environment. however, need special libraries tweepy
don't installed default. thus, have let heroku know install these.
you'll need use pip , requirements.txt document lists out libraries trying use version numbers.
Comments
Post a Comment