Skip to content

Instantly share code, notes, and snippets.

@russau
Last active Jul 16, 2020
Embed
What would you like to do?
An API for blinking lights
openapi: "3.0.0"
info:
title: Lights
version: "1.0"
servers:
- url: http://localhost:9090/v1.0
paths:
/random:
post:
summary: Display a random color
description: Display a random color
operationId: lights.post_random
responses:
200:
description: random color
/health:
get:
summary: Health
description: Health
operationId: lights.health
responses:
200:
description: health check
#!/usr/bin/env python3
from time import sleep
import connexion
import blinkt
from random import randrange
def post_random():
blinkt.set_brightness(0.1)
blinkt.set_all(randrange(100), randrange(100), randrange(100))
blinkt.show()
sleep(0.1)
blinkt.set_all(0, 0, 0)
blinkt.show()
def health():
blinkt.set_brightness(0.1)
blinkt.set_pixel(0, 100, 0, 0)
blinkt.show()
sleep(0.01)
blinkt.set_pixel(0, 0, 0, 0)
blinkt.show()
return "ok"
if __name__ == '__main__':
app = connexion.FlaskApp(__name__, port=9090)
app.add_api('lights-api.yaml', arguments={'title': 'Hello World Example'})
app.run()
connexion[swagger-ui]
connexion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment