add base for python elstat

This commit is contained in:
Luna Mendes 2018-07-07 19:46:28 -03:00
parent f8269c8aec
commit 78ae8f27f0
5 changed files with 70 additions and 14 deletions

View File

@ -1,21 +1,17 @@
# 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`:
```elixir
def deps do
[
{:elstat, "~> 0.1.0"}
]
end
```
git clone https://gitlab.com/elixire/elstat
cd elstat
python3.6 -m pip install -Ur requirements.txt
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/elstat](https://hexdocs.pm/elstat).
## Run
```
python3.6 run.py
```

1
blueprints/__init__.py Normal file
View File

@ -0,0 +1 @@
from .api import bp as api

13
blueprints/api.py Normal file
View File

@ -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

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
git+https://github.com/channelcat/sanic@f9b29fd7e746301624d3d1a3501b1c47287eb297
sanic-cors==0.9.4
aiohttp==3.3.2

43
run.py Normal file
View File

@ -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)