File size: 2,543 Bytes
6b83428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- 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