123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- from flask import Flask, render_template
- from flask_paginate import Pagination, get_page_parameter, get_page_args
- from flask_caching import Cache
- from flask import request
- import pendulum
- app = Flask(__name__)
- @app.template_filter("datefmt")
- def format_datetime(value):
- dt = pendulum.from_timestamp(value, tz=pendulum.tz.local_timezone())
- return dt.to_datetime_string()
- # Check Configuring Flask-Caching section for more details
- cache = Cache(app, config={"CACHE_TYPE": "filesystem", "CACHE_DIR": "cache"})
- import jammin
- bases = {"FSX_GEN": "fsx_bot", "FSX_BOT": "fsx_bot"}
- @cache.cached(timeout=50, key_prefix="messages")
- def get_messages(base):
- return jammin.get_messages(base)
- @app.route("/list")
- def list_bases():
- return render_template("list.html", bases=bases)
- # return 'Here would be a listing of message bases'
- @app.route("/messages/<area>")
- def display_messages(area):
- if area not in bases:
- return render_template("missing-area.html")
- # messages = jammin.get_messages(bases[area])
- messages = get_messages(bases[area])
- messages.reverse()
- page = request.args.get(get_page_parameter(), type=int, default=1)
- # get_page_arg defaults to page 1, per_page of 10
- PER_PAGE = 50
- total = len(messages)
- pagination = Pagination(
- page=page,
- total=total,
- css_framework="foundation",
- record_name="messages",
- per_page=PER_PAGE,
- )
- page, per_page, offset = get_page_args()
- start = (page - 1) * PER_PAGE
- end = start + PER_PAGE
- # messages = messages[(page-1) * PER_PAGE:offset+PER_PAGE]
- messages = messages[start:end]
- return render_template(
- "messages.html", messages=messages, area=area, pagination=pagination
- )
- @app.route("/read/<area>/<int:msgno>")
- def display_message(area, msgno):
- if area not in bases:
- return render_template("missing-area.html")
- message = jammin.read_message(bases[area], msgno)
- if "text" in message:
- message["text"] = message["text"].replace("\r", "\n") # <br >\n")
- return render_template("message.html", message=message, area=area, msgnumber=msgno)
|