add base for python elstat
This commit is contained in:
parent
f8269c8aec
commit
78ae8f27f0
24
README.md
24
README.md
|
@ -1,21 +1,17 @@
|
||||||
# Elstat
|
# Elstat
|
||||||
|
|
||||||
**TODO: Add description**
|
Status page software.
|
||||||
|
|
||||||
## Installation
|
## Installing
|
||||||
|
|
||||||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
|
```
|
||||||
by adding `elstat` to your list of dependencies in `mix.exs`:
|
git clone https://gitlab.com/elixire/elstat
|
||||||
|
cd elstat
|
||||||
```elixir
|
python3.6 -m pip install -Ur requirements.txt
|
||||||
def deps do
|
|
||||||
[
|
|
||||||
{:elstat, "~> 0.1.0"}
|
|
||||||
]
|
|
||||||
end
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
## Run
|
||||||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
|
||||||
be found at [https://hexdocs.pm/elstat](https://hexdocs.pm/elstat).
|
|
||||||
|
|
||||||
|
```
|
||||||
|
python3.6 run.py
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
from .api import bp as api
|
|
@ -0,0 +1,13 @@
|
||||||
|
from sanic import Blueprint, response
|
||||||
|
|
||||||
|
bp = Blueprint(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.get('/api/current_status')
|
||||||
|
async def get_cur_status(request):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@bp.get('/api/status')
|
||||||
|
async def get_full_status(request):
|
||||||
|
pass
|
|
@ -0,0 +1,3 @@
|
||||||
|
git+https://github.com/channelcat/sanic@f9b29fd7e746301624d3d1a3501b1c47287eb297
|
||||||
|
sanic-cors==0.9.4
|
||||||
|
aiohttp==3.3.2
|
|
@ -0,0 +1,43 @@
|
||||||
|
import logging
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
from sanic import Sanic, response
|
||||||
|
from sanic_cors import CORS
|
||||||
|
from sanic.exceptions import NotFound, FileNotFound
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
app = Sanic()
|
||||||
|
app.cfg = config
|
||||||
|
CORS(app, automatic_options=True)
|
||||||
|
|
||||||
|
|
||||||
|
@app.listener('before_server_start')
|
||||||
|
async def _app_start(refapp, loop):
|
||||||
|
refapp.session = aiohttp.ClientSession(loop=loop)
|
||||||
|
refapp.conn = sqlite3.connect('elstat.db')
|
||||||
|
|
||||||
|
|
||||||
|
@app.listener('after_server_stop')
|
||||||
|
async def _app_stop(refapp, _loop):
|
||||||
|
refapp.conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@app.exception(Exception)
|
||||||
|
async def _handle_exc(request, exception):
|
||||||
|
status_code = 404 if isinstance(exception, (NotFound, FileNotFound)) \
|
||||||
|
else 500
|
||||||
|
|
||||||
|
return response.json({
|
||||||
|
'error': True,
|
||||||
|
'message': repr(exception)
|
||||||
|
}, status=status_code)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.static('/', './priv/frontend/build')
|
||||||
|
app.static('/', './priv/frontend/build/index.html')
|
||||||
|
|
||||||
|
app.run(port=config.PORT)
|
Loading…
Reference in New Issue