Skip to content

Commit

Permalink
changed mongodb connection to URI
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Caylor committed Apr 7, 2016
1 parent 1804e15 commit a49de41
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 67 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ venv
.env_dev_heroku
.env_prod_heroku

# Ignoring requirements.txt for this app, because of miniconda:
requirements.txt

# Utility scripts for Kelly (and Gist):
config.codekit
.codekit-cache
Expand Down
67 changes: 44 additions & 23 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,53 @@
"""Configuration for tower app."""
import os

basedir = os.path.abspath(os.path.dirname(__file__))


def make_mongo_uri(
host='localhost',
port=27017,
database='default',
replica_set=None,
username=None,
password=None):
"""Make the mongo connection URI."""
uri = 'mongodb://'
if username is not None and password is not None:
uri += username + ':' + password + '@'
if ',' in host:
host = host.split(',')
if not isinstance(host, basestring):
if port is not None:
host = [x + ':' + str(port) for x in host]
uri += ",".join(host)
else:
uri += host
if port is not None:
uri += ':' + str(port)
if database is not None:
uri += '/' + database
if replica_set is not None:
uri += '?replicaSet=' + replica_set
return uri


class Config:
"""Configuration class for tower app."""

SECRET_KEY = os.environ.get('APP_SECRET')
ROOT_DIR = os.environ.get('ROOT_DIR')
SLACK_TOKEN = os.environ.get('SLACK_TOKEN')

@staticmethod
def init_app(app):
"""Initialize the config."""
pass

def mongo_url(self):

if self.MONGODB_SETTINGS['username'] is '':
return 'mongodb://' + self.MONGODB_SETTINGS['host'] + \
':' + str(self.MONGODB_SETTINGS['port']) + \
'/' + self.MONGODB_SETTINGS['db']
else:
return 'mongodb://' + self.MONGODB_SETTINGS['username'] + \
':' + self.MONGODB_SETTINGS['password'] + \
'@' + self.MONGODB_SETTINGS['host'] + \
':' + str(self.MONGODB_SETTINGS['port']) + \
'/' + self.MONGODB_SETTINGS['db']


class TestingConfig(Config):
"""Test configuration settings."""

TESTING = True
SERVER_NAME = '0.0.0.0:5000'
MONGODB_SETTINGS = {
Expand All @@ -39,20 +60,20 @@ class TestingConfig(Config):


class DevelopmentConfig(Config):
"""Development configuration settings."""

ROOT_DIR = os.environ.get('ROOT_DIR')
SERVER_NAME = 'mpala.herokuapp.com'
DEBUG = True
# MONGODB_DB = os.environ.get('MONGODB_DEV_DATABASE')
# MONGODB_USERNAME = os.environ.get('MONGODB_DEV_USER')
# MONGODB_PASSWORD = os.environ.get('MONGODB_DEV_PASSWORD')
# MONGODB_HOST = os.environ.get('MONGODB_DEV_HOST')
# MONGODB_PORT = int(os.environ.get('MONGODB_DEV_PORT'))
MONGODB_SETTINGS = {
"db": os.environ.get('MONGODB_DEV_DATABASE'),
"username": os.environ.get('MONGODB_DEV_USER'),
"password": os.environ.get('MONGODB_DEV_PASSWORD'),
"host": os.environ.get('MONGODB_DEV_HOST'),
"port": int(os.environ.get('MONGODB_DEV_PORT'))
"HOST": make_mongo_uri(
host=os.environ.get('MONGODB_DEV_HOST'),
port=int(os.environ.get('MONGODB_DEV_PORT')),
database=os.environ.get('MONGODB_DEV_DATABASE'),
username=os.environ.get('MONGODB_DEV_USER'),
password=os.environ.get('MONGODB_DEV_PASSWORD'),
replica_set=os.environ.get('MONGODB_DEV_REPLICASET')
)
}

config = {
Expand Down
88 changes: 44 additions & 44 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
Flask==0.10.1
Flask-Bootstrap==3.3.2.1
Flask-Bower==1.1.1
Flask-Login==0.3.2
Flask-Moment==0.4.0
Flask-Script==2.0.5
Flask-WTF==0.11
Jinja2==2.7.3
MarkupSafe==0.23
WTForms==2.0.2
Werkzeug==0.10.4
amqp==1.4.9
anyjson==0.3.3
billiard==3.3.0.23
celery==3.1.23
# Flask==0.10.1
# Flask-Bootstrap==3.3.2.1
# Flask-Bower==1.1.1
# Flask-Login==0.3.2
# Flask-Moment==0.4.0
# Flask-Script==2.0.5
# Flask-WTF==0.11
# Jinja2==2.7.3
# MarkupSafe==0.23
# WTForms==2.0.2
# Werkzeug==0.10.4
# amqp==1.4.9
# anyjson==0.3.3
# billiard==3.3.0.23
# celery==3.1.23
# cffi==1.1.2
cryptography==0.9.1
docopt==0.6.2
dropbox==2.2.0
enum34==1.0.4
fake-factory==0.5.0
flask-mongoengine==0.7.1
idna==2.0
ipaddress==1.0.7
itsdangerous==0.24
kombu==3.0.35
mglob==0.4
mongoengine==0.9.0
ndg-httpsclient==0.4.0
# cryptography==0.9.1
# docopt==0.6.2
# dropbox==2.2.0
# enum34==1.0.4
# fake-factory==0.5.0
# flask-mongoengine==0.7.1
# idna==2.0
# ipaddress==1.0.7
# itsdangerous==0.24
# kombu==3.0.35
# mglob==0.4
# mongoengine==0.9.0
# ndg-httpsclient==0.4.0
# netCDF4==1.1.7.1
nose==1.3.6
# nose==1.3.6
# numpy==1.8.0
# pandas==0.16.0
pip-pop==0.1.0
pyOpenSSL==0.15.1
pyandoc==0.0.1
pyasn1==0.1.8
pycparser==2.14
pymongo==2.8
python-dateutil==2.4.2
pytz==2015.2
redis==2.10.5
requests==2.7.0
# pip-pop==0.1.0
# pyOpenSSL==0.15.1
# pyandoc==0.0.1
# pyasn1==0.1.8
# pycparser==2.14
# pymongo==2.8
# python-dateutil==2.4.2
# pytz==2015.2
# redis==2.10.5
# requests==2.7.0
# scipy==0.15.1
six==1.9.0
slacker==0.6.2
urllib3==1.10.3
waitress==0.8.9
wsgiref==0.1.2
# six==1.9.0
# slacker==0.6.2
# urllib3==1.10.3
# waitress==0.8.9
# wsgiref==0.1.2
# xarray==0.7.2
6 changes: 6 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ def create_metadata_task(self, year, doy):
doy=doy,
files=find_files(year=year, doy=doy)
).generate_metadata()


@celery.task(bind=True)
def process_smap_data(self):
"""Update SMAP data and upload to FTP server."""
self.update_state(state='PROGRESS')

0 comments on commit a49de41

Please sign in to comment.