Skip to content

A visual plug-in for displaying native state through echarts for browser.

License

Notifications You must be signed in to change notification settings

hoorace/flask-state

 
 

Repository files navigation

Flask-State

Flask-States is a visual plug-in based on flask. It can record the local state every minute and read redis status (optional),and generate data chart to show to users through Echarts.

Installation

Install and update using pip:

$ pip install Flask-State

Usage

After the Flask-State is installed, you also need to import JavaScript files and CSS files to bind a convention ID value for your element, which can be used easily. In some configurations, you can also choose to modify them.

Firstly:we'll set up a Flask app.

import flask

app = flask.Flask(__name__)

Secondly:Call the init_app method of the Flask-State to initialize the relevant configuration. It will add several routes for you to access some configurations and databases.

import flask_state

flask_state.init_app(app)

Thirdly:Introduce related files into your HTML file and bind ID values for an element.

<link href="https://cdn.jsdelivr.net/gh/yoobool/[email protected]/flask_state/static/flask_state.css" rel="stylesheet">

<!-- Any element: div/button/a/span -->
<a id='console_machine_status'></a>

<script src="https://cdn.staticfile.org/echarts/4.2.1/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/yoobool/[email protected]/flask_state/static/flask_state.js"></script>

Extra:You can also customize some configuration files.

# If you still need to monitor the redis status, you need to configure your redis status on the Flask app
app.config['REDIS_CONF'] = {'REDIS_STATE': True, 'REDIS_HOST': '192.168.1.2', 'REDIS_PORT':16379, 'REDIS_PASSWORD': 'fish09'}
from flask_state import default_conf_obj

# ADDRESS is the database name
# CATALOGUE 0 is the same level directory as Flask config, and 1 is the superior directory of Flask config
ADDRESS = 'console_host'
default_conf_obj.set_address(ADDRESS)
from flask_state import default_conf_obj

# SECS is the time interval for recording the local state, with a minimum interval of 10 seconds
SECS = 60
default_conf_obj.set_secs(SECS)

Contributing

Welcome to open an issue!

Flask-State follows the Contributor Covenant Code of Conduct.

License

Flask-State is available under the BSD-3-Clause License.

About

A visual plug-in for displaying native state through echarts for browser.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 69.5%
  • Python 25.9%
  • CSS 4.6%