|
|
|
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 |
|
|
|
|
|
|
|
|
|
setup_logging() |
|
log = logging.getLogger(__name__) |
|
|
|
|
|
def create_the_database(db): |
|
db.create_all() |
|
|
|
|
|
|
|
|
|
SQLPROTOCOL = "mysql://" |
|
SQLUNAME = "root" |
|
SQLPASS = "" |
|
SQLHOST = "localhost" |
|
SQLDB = "nowcasting" |
|
|
|
app = Flask(__name__) |
|
app.config["SECRET_KEY"] = "A secret for nowcasting in SIH" |
|
|
|
all_methods = ["GET", "POST"] |
|
|
|
|
|
app.add_url_rule("/", view_func=routes.index) |
|
|
|
app.add_url_rule("/submitted", methods=all_methods, view_func=routes.submitted) |
|
|
|
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 |
|
app.config[ |
|
"SQLALCHEMY_DATABASE_URI" |
|
] = "${SQLPROTOCOL}${SQLUNAME}:${SQLPASS}@${SQLHOST}/${SQLDB}" |
|
db = SQLAlchemy(app) |
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
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: |
|
|
|
app.run(debug=args.debug) |
|
except Exception as e: |
|
print("Error in main.py:", e) |
|
traceback.print_exc() |
|
raise e |
|
|