import os os.environ["DJANGO_SETTINGS_MODULE"] = "whispermaphone.settings" import django from django.template.loader import render_to_string from django.utils import timezone from django.conf import settings django.setup() from main.models import Thought from jetforce import GeminiServer, JetforceApplication, Response, Status from decouple import config app = JetforceApplication() @app.route("", strict_trailing_slash=False) def index(request): thoughts = Thought.objects.order_by("-posted") for thought in thoughts: thought.timezone = timezone.get_fixed_timezone(-thought.timezone_offset) offset_hours = -thought.timezone_offset / 60 if offset_hours == int(offset_hours): offset_hours = int(offset_hours) if offset_hours > 0: offset_hours = "+" + str(offset_hours) thought.offset_hours = offset_hours rendered_text = render_to_string("whispermaphone/index.gmi", { "thoughts": thoughts, }) return Response(Status.SUCCESS, "text/gemini", rendered_text) @app.route("/about", strict_trailing_slash=False) def about(request): return Response(Status.SUCCESS, "text/gemini", render_to_string("whispermaphone/about.gmi")) if __name__ == "__main__": server = GeminiServer( app=app, host="0.0.0.0", hostname=("localhost" if settings.DEBUG else settings.ALLOWED_HOSTS[0]), certfile=config("CERTFILE", default=None), keyfile=config("KEYFILE", default=None), port=1973 ) server.run()