Skip to content
display.py 2.82 KiB
Newer Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''REST API for fits files'''

# System modules
import time

# Third-party modules
from astropy.time import Time
from flask import Response, make_response, render_template, request
from flask_restx import Namespace, Resource, fields

# Custom modules

############################
# REST API
############################

api = Namespace('display', description='Fits files related operations')


# @api.route("/position")
# class Pointing(Resource):
#     """Position of the webcam."""

#     def get(self):
#         """Retrieve the alt az coordinates of the webcam."""
#         res = {
#             "response": devices.ipcam.altaz,
#             "error": devices.ipcam.error,
#         }
#         return res

#     def put(self):
#         """Set new alt az coordinates of the webcam."""
#         target = api.payload
#         devices.ipcam.altaz = target
#         res = {
#             "response": devices.ipcam.altaz,
#             "error": devices.ipcam.error,
#         }
#         return res

Davide Ricci's avatar
Davide Ricci committed
# @api.route("/test2")
# class Pointing(Resource):
#     """test."""
    
#     def get(self):
#         """BSON test"""
        
#         res = {
#             "response": (1.234*1+np.zeros((100,100))).tolist(),
#             "error": (1.234*1+np.zeros((100,100))).tolist(),
#         }
        
#         # Convert JSON to binary
#         b = msgpack.packb(res)
#         #json.dumps(res).encode('utf-8')
        
#         response = make_response(b)
#         response.headers['Content-Type'] = 'application/octet-stream'
        
#         return response

    # def put(self):
    #     """Set new alt az coordinates of the webcam."""
    #     target = api.payload
    #     res = {
    #         "response": devices.ipcam.altaz,
    #         "error": devices.ipcam.error,
    #     }
    #     return res


# @api.route("/snapshot")
# class Snapshot(Resource):
#     """Image from the webcam."""

#     def __init__(self, *args, **kwargs):
#         '''Constructor.'''
#         super().__init__(self)
#         self.last = None

#     def get(self):
#         """Retrieve a raw base/64 image from the webcam."""

#         img =  devices.ipcam.image
#         if not img:
#             code = 401
#         elif devices.ipcam.error:
#             code = 501
#         else:
#             code = 200
        
#         res = {
#             "response": img.decode("ISO-8859-1") if img else img,
#             "error": devices.ipcam.error,
#         }
        
#         self.last = img
#         return res, code



############################
# WEB VIEW
############################

web = Namespace('display', description='Display fits file interface')


@web.route("/")
class Init(Resource):

    def get(self):
        data = {}
        return make_response(render_template("display.html", data=data))