moved initial fetch to fetch_job module and renamed parser to analyzer
This commit is contained in:
+4
-10
@@ -4,14 +4,14 @@ logging.basicConfig(level=logging.INFO)
|
||||
from flask import Flask, jsonify, render_template
|
||||
import os, sys, time
|
||||
|
||||
from src.parser import (
|
||||
from src.anayzer import (
|
||||
calculate_totals,
|
||||
get_last_n_days,
|
||||
get_stats,
|
||||
)
|
||||
from src.cache import Cache
|
||||
from src.web_calendar import Calendar
|
||||
from src.fetch_job import background_fetch_job
|
||||
from src.fetch_job import initial_fetch, background_fetch_job
|
||||
from src import config
|
||||
|
||||
app = Flask(__name__)
|
||||
@@ -19,14 +19,6 @@ sessions_cache = Cache()
|
||||
calendar = Calendar()
|
||||
daemon = BGFetchJob()
|
||||
|
||||
# initial data fetch (required to work)
|
||||
try:
|
||||
sessions = calendar.fetch_sessions_since(config.CURRENT_SEMESTER_START)
|
||||
sessions_cache.set(sessions)
|
||||
except Exception:
|
||||
app.logger.exception("Failed to fetch from calDAV server.")
|
||||
sys.exit(1)
|
||||
|
||||
# web ui
|
||||
@app.route("/")
|
||||
def index():
|
||||
@@ -52,6 +44,8 @@ def api_dashboard():
|
||||
def api_sessions():
|
||||
return jsonify(sessions_cache.get())
|
||||
|
||||
# data
|
||||
initial_fetch(calendar, sessions_cache)
|
||||
daemon.run((calendar, sessions_cache))
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -6,6 +6,15 @@ FILE_LOCK_PATH = "/tmp/fetch_job.lock"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def initial_fetch(calendar, sessions_cache):
|
||||
try:
|
||||
sessions = calendar.fetch_sessions_since(config.CURRENT_SEMESTER_START)
|
||||
sessions_cache.set(sessions)
|
||||
except Exception:
|
||||
logger.exception("Failed to fetch from calDAV server.")
|
||||
sys.exit(1)
|
||||
|
||||
def background_fetch_job(calendar, sessions_cache):
|
||||
while True:
|
||||
time.sleep(config.REFETCH_SECONDS)
|
||||
|
||||
Reference in New Issue
Block a user