#!/usr/bin/env python

from flask import Flask, redirect, url_for, request
from flask_apscheduler import APScheduler
from astropy.time import Time

class Ciccio:
    def __init__(self):
        self.attr = []

    def update(self):
        self.attr = Time.now()
        
# set configuration values
class Config:
    SCHEDULER_API_ENABLED = True

# create app
app = Flask(__name__)
#app.config.from_object(Config())

# initialize scheduler
scheduler = APScheduler()
# if you don't wanna use a config, you can set options here:
scheduler.api_enabled = True
scheduler.init_app(app)

ciccio = Ciccio()
# interval example
@scheduler.task('interval', id='do_job_1', seconds=5, misfire_grace_time=900)
def job1():
    ciccio.update()
    print('Job 1 executed')


# cron examples
@scheduler.task('interval', id='do_job_2', seconds=1)
def job2():
    print("Job2 : "+str(ciccio.attr))


@app.route('/clock')
def success():
    return str(ciccio.attr)

scheduler.start()


if __name__ == '__main__':
    app.run()
