Skip to content

Commit

Permalink
app:create_app()
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Li authored and Steven Li committed Oct 14, 2024
1 parent 4af84f1 commit 6186a7a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
34 changes: 17 additions & 17 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

db = SQLAlchemy()

# Define SmartBinData model
class SmartBinData(db.Model):
__tablename__ = 'mockdata'
__table_args__ = {'schema': 'smartbin'} # Specify the schema if needed
bin_id = db.Column(db.String(10), primary_key=True, nullable=False)
latitude = db.Column(db.Numeric(12, 8))
longitude = db.Column(db.Numeric(12, 8))
collection_frequency_per_month = db.Column(db.Integer)
average_collection_time_days = db.Column(db.Integer)
tilt_status = db.Column(db.String(20))
fill_level_percentage = db.Column(db.Numeric(5, 2))
temperature_celsius = db.Column(db.Numeric(5, 2))
displacement = db.Column(db.String(20))
days_since_last_emptied = db.Column(db.Integer)
communication_status = db.Column(db.String(20))
battery_level_percentage = db.Column(db.Numeric(4, 2))

def create_app():
app = Flask(__name__)

Expand All @@ -21,23 +38,6 @@ def create_app():

db.init_app(app)

# Define SmartBinData model
class SmartBinData(db.Model):
__tablename__ = 'mockdata'
__table_args__ = {'schema': 'smartbin'} # Specify the schema if needed
bin_id = db.Column(db.String(10), primary_key=True, nullable=False)
latitude = db.Column(db.Numeric(12, 8))
longitude = db.Column(db.Numeric(12, 8))
collection_frequency_per_month = db.Column(db.Integer)
average_collection_time_days = db.Column(db.Integer)
tilt_status = db.Column(db.String(20))
fill_level_percentage = db.Column(db.Numeric(5, 2))
temperature_celsius = db.Column(db.Numeric(5, 2))
displacement = db.Column(db.String(20))
days_since_last_emptied = db.Column(db.Integer)
communication_status = db.Column(db.String(20))
battery_level_percentage = db.Column(db.Numeric(4, 2))

# Route to check if the app is running
@app.route('/')
def index():
Expand Down
4 changes: 3 additions & 1 deletion mqtt_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import os
import json
import base64
from app import app, db, SmartBinData
import logging
import sys
from threading import Thread
from app import create_app, db, SmartBinData

app = create_app()

# Setup logging to print to stdout
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
Expand Down
4 changes: 2 additions & 2 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ nohup python3 mqtt_subscriber.py &
# Get the PORT environment variable
PORT=${PORT:-6969} # Default to 6969 if PORT is not set

# Start the Flask application using Gunicorn
exec gunicorn --bind 0.0.0.0:$PORT app:app
# Start the Flask application using Gunicorn with the create_app() function
exec gunicorn --bind 0.0.0.0:$PORT "app:create_app()"

0 comments on commit 6186a7a

Please sign in to comment.