-
Install necessary packages, best in a virtualenv. Do
pip install -r requirements.txt
-
Modify configuration settings, copy the
config.example.py
-file toconfig.py
and fill it in. To acquire OAuth-credentials, mail [email protected]. Make sure you're in debug when the NXT is not connected. -
Initialize database with alembic, execute the following command
python slotmachien.py db upgrade
-
To start developing, add yourself to the database. Open a python shell and execute the following commands:
from models import User, db
admin = User()
admin.configure('<your Zeus OAuth name>', True, True)
db.session.add(admin)
# commit all the things
db.session.commit()
- Run the server on your computer with
python slotmachien.py runserver
After that you can go to localhost:/admin, and login to the admin interface, and add an AuthKey for the slack requests.
Get the authorization code by authenticating @ login
Send a GET request to /slotmachien/
or send the send status
with update door,
if the header is set to Content-Type: application/json
then a JSON is returned,
otherwise you're redirected to /slotmachien/admin/
.
Send a POST request to /slotmachien/
Header set the Content-Type: application/json
and Authorization: <token>
With payload
{
"action": <action>
}
Possible action keywords are: open, close, status
If the HTTP status is 200, then we respond with a json, 2 kinds when succesfull:
{
"status": <current status>
}
Possibilities: open
and closed
Error:
{
"error": "error message as string"
}
If the HTTP status code is 401, authentication failed.
Login using the link.
If the HTTP status is 200, then we respond with a json, when succesull, if the header has Content-Type: application/json
:
{
"token": <new generated token>
}
Error:
{
"error": "error message as string"
}
If the HTTP status code is 401, authentication failed.
You have to run the slotmachien.fcgi program. Than add the following configuration to nginx:
location / {
try_files $uri @slotmachien;
}
location @slotmachien {
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_NAME "";
fastcgi_pass unix:/tmp/slotmachien.sock;
}
Copy the slotmachien-fastcgi.sh
to the /etc/init.d/
directory as slotmachien
Default in demo files:
class Configuration(object):
SQLALCHEMY_DATABASE_URI = 'sqlite:///slotmachien.db'
DEBUG = False
SECRET_KEY = '<s3r3t>'
SLACK_WEBHOOK = 'https://zeuswpi.slack.com/services/hooks/incoming-webhook?token=<s3cr3t>'
PROCESS = 'cd /home/slotmachien/slotmachien/SlotMachienPC/bin && /opt/leJOS_NXT/bin/nxjpc PCMain'
LOGFILE = '/var/log/slotmachien.log'
GITHUB_KEY = '<not-so-secret>'
GITHUB_SECRET = '<super-secret>'