Spaces:
Sleeping
Sleeping
# -*- coding: utf-8 -*- | |
import argparse | |
import logging | |
import os | |
import traceback | |
import routes | |
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
from libs.utils import setup_logging | |
# from marshmallow import Schema, fields | |
setup_logging() | |
log = logging.getLogger(__name__) | |
def create_the_database(db): | |
db.create_all() | |
# =============================================================================== | |
SQLPROTOCOL = "mysql://" # "sqlite:////" | |
SQLUNAME = "root" | |
SQLPASS = "" | |
SQLHOST = "localhost" | |
SQLDB = "nowcasting" | |
app = Flask(__name__) | |
app.config["SECRET_KEY"] = "A secret for nowcasting in SIH" | |
all_methods = ["GET", "POST"] | |
# Home page (where you will add a new user) | |
app.add_url_rule("/", view_func=routes.index) | |
# "Thank you for submitting your form" page | |
app.add_url_rule("/submitted", methods=all_methods, view_func=routes.submitted) | |
# Viewing all the content in the database page | |
app.add_url_rule("/database", view_func=routes.view_database) | |
app.add_url_rule( | |
"/modify<the_id>/<modified_category>", | |
methods=all_methods, | |
view_func=routes.modify_database, | |
) | |
app.add_url_rule("/delete<the_id>", methods=all_methods, view_func=routes.delete) | |
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False # no warning messages | |
app.config[ | |
"SQLALCHEMY_DATABASE_URI" | |
] = "${SQLPROTOCOL}${SQLUNAME}:${SQLPASS}@${SQLHOST}/${SQLDB}" | |
db = SQLAlchemy(app) | |
# =============================================================================== | |
# =============================================================================== | |
if __name__ == "__main__": | |
# Load Configs | |
parser = argparse.ArgumentParser( | |
description="Download rainfall data from Google Earth Engine for a range of dates.", | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | |
) | |
parser.add_argument( | |
"-i", | |
"--input", | |
help="Absolute or relative path to the netcdf data directory for each farm. Should be in this format: '/path/to/farm/{}/soilwatermodel'", | |
default=os.path.join( | |
os.path.expanduser("~"), "Data/results_default/{}/soilwatermodel" | |
), | |
) | |
parser.add_argument( | |
"-d", | |
"--debug", | |
help="Debug mode as True or False. Default is True.", | |
default=True, | |
) | |
args = parser.parse_args() | |
INPUT = args.input | |
try: | |
# dashapp.run_server(debug=args.debug) | |
app.run(debug=args.debug) | |
except Exception as e: | |
print("Error in main.py:", e) | |
traceback.print_exc() | |
raise e | |