Git Product home page Git Product logo

rpisurv-api's People

Contributors

guiguiabloc avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

rpisurv-api's Issues

FEATURE REQUEST: JQ output & status

First, thank you!

Second, two things more useful to me, coded/attached, in case you want to use my code:

  1. /camera/status - to see which camera we're using
  2. output in JQ format, which would allow an external service to know status, make change, confirm change, etc.

needs to be able to read/write to /tmp for status.

# Gruik coded by GuiguiAbloc
# Flask version 1.1.0 or better required
import flask
import time
import keyboard
app = flask.Flask(__name__)


@app.route('/')
def index():
  return 'Server Works!'

@app.route('/camera/pause')
def campause():
  try:
      text_file = open("/tmp/rpi.status", "w")
      text_file.write('pause')
      text_file.close()
      text_file = open("/tmp/rpi.camera", "r")
      rcamera = text_file.read()
      text_file.close()
      keyboard.press_and_release('p')
      return {
          "status": "pause",
          "camera": rcamera,
      }
  except:
      print("Error")
      return "Error"

@app.route('/camera/resume')
def camresume():
  try:
      text_file = open("/tmp/rpi.status", "w")
      text_file.write('resume')
      text_file.close()
      text_file = open("/tmp/rpi.camera", "r")
      rcamera = text_file.read()
      text_file.close()
      keyboard.press_and_release('r')
      return {
          "status": "resume",
          "camera": rcamera,
      }
  except:
      print("Error")
      return "Error"

@app.route('/camera/status')
def camstatus():
   try:
      text_file = open("/tmp/rpi.status", "r")
      rstatus = text_file.read()
      text_file.close()
      text_file = open("/tmp/rpi.camera", "r")
      rcamera = text_file.read()
      text_file.close()
      return {
          "status": rstatus,
          "camera": rcamera
      }
   except:
      print("Error")
      return "Error"

@app.route('/camera/1')
def cam1():
  try:
      text_file = open("/tmp/rpi.status", "r")
      rstatus = text_file.read()
      text_file.close()
      text_file = open("/tmp/rpi.camera", "w")
      text_file.write('1')
      text_file.close()
      keyboard.press_and_release('F1')
      return {
          "status": rstatus,
          "camera": "1",
      }
  except:
      print("Error")
      return "Error"

@app.route('/camera/2')
def cam2():
  try:
      text_file = open("/tmp/rpi.status", "r")
      rstatus = text_file.read()
      text_file.close()
      text_file = open("/tmp/rpi.camera", "w")
      text_file.write('2')
      text_file.close()
      keyboard.press_and_release('F2')
      return {
          "status": rstatus,
          "camera": "2",
      }
  except:
      print("Error")
      return "Error"

@app.route('/camera/3')
def cam3():
  try:
      text_file = open("/tmp/rpi.status", "r")
      rstatus = text_file.read()
      text_file.close()
      text_file = open("/tmp/rpi.camera", "w")
      text_file.write('3')
      text_file.close()
      keyboard.press_and_release('F3')
      return {
          "status": rstatus,
          "camera": "3",
      }
  except:
      print("Error")
      return "Error"

@app.route('/camera/4')
def cam4():
  try:
      text_file = open("/tmp/rpi.status", "r")
      rstatus = text_file.read()
      text_file.close()
      text_file = open("/tmp/rpi.camera", "w")
      text_file.write('4')
      text_file.close()
      keyboard.press_and_release('F4')
      return {
          "status": rstatus,
          "camera": "4",
      }
  except:
      print("Error")
      return "Error"

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=False)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.