Example #1
0
def add_data():
    """
    Add new data into database
    The default cases and death will be 0
    """
    postForm = json.loads(request.get_data(as_text=True))

    if not postForm:
        return jsonify({'Error': 'Empty request body!'}), 400

    data = []
    message = []
    for form in postForm:
        if not 'date' in form:
            return jsonify({'Error': 'Please specify the date!'}), 400
        # Set default value for cases and death
        form.setdefault('cases', 0)
        form.setdefault('death', 0)
        new_data = Data(form['date'], form['cases'], form['death'])
        data.append(new_data)
        message.append(form['date'])

    try:
        db.session.add_all(data)
        db.session.commit()
    except Exception as e:
        return jsonify({'Error': repr(e)}), 409

    return jsonify({'Message': 'Add new item in date {}'.format(message)}), 201
Example #2
0
    def __init__(self):
        # inherit from parent class, setup UI
        super(self.__class__, self).__init__()
        self.setupUi(self)

        # set up data model
        self.dataModel = Data.DataModel(self)
        self.mainTableView.setModel(self.dataModel)

        # map button bindings
        self.addButton.clicked.connect(self.add_button)
        self.removeButton.clicked.connect(self.remove_button)
Example #3
0
def get_daily_report():
    """
    Send an email with a picture that contains a trend of cases and death
    """
    admin = Admin.query.get(admin_auth.current_user())
    path = Data.create_picture()
    text = 'Hi {}, this is the latest daily report.'.format(admin.username)
    # Invoke email service
    is_successful, message = email_service.send_image(admin.email,
                                                      'Daily report', text,
                                                      path)
    if is_successful:
        return jsonify({"Info": "Success"}), 200
    else:
        return jsonify({"Error info": str(message)}), 400
Example #4
0
def query_by_date(date):
    """
    Query the data by date
    """
    return Data.query_data(date)
Example #5
0
def query():
    """
    Query all data
    """
    return Data.query_data()