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
# import devices
############################
# 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
# @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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# @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))