From 0e2fcf3195a2919ca9ea808cc2adedd4af7ff743 Mon Sep 17 00:00:00 2001 From: clerie Date: Tue, 13 Jun 2023 12:30:20 +0200 Subject: [PATCH] Init repository --- .gitignore | 2 ++ README.md | 21 ++++++++++++ assets/style.css | 43 +++++++++++++++++++++++++ chaosevents.py | 77 ++++++++++++++++++++++++++++++++++++++++++++ flake.lock | 27 ++++++++++++++++ flake.nix | 40 +++++++++++++++++++++++ pyproject.toml | 34 +++++++++++++++++++ templates/index.html | 43 +++++++++++++++++++++++++ 8 files changed, 287 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 assets/style.css create mode 100755 chaosevents.py create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 pyproject.toml create mode 100644 templates/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94280ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +html +result diff --git a/README.md b/README.md new file mode 100644 index 0000000..774984f --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Chaos Events + +This repository contains code that generates the [Chaos Events Website](https://chaosevents.clerie.de). + +If fetches an ICS from a URL and generates html files that get placed in a specified directory. + +## Use with pip + +``` +pip install . +``` + +``` +chaosevents path/to/out/directory +``` + +## Use with flake + +``` +nix run . -- path/to/out/directory +``` diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..4ccacb2 --- /dev/null +++ b/assets/style.css @@ -0,0 +1,43 @@ +* { + padding: 0; + margin: 0; +} + +body { + font-family: Arial, Helvetica, sans-serif; +} + +.container { + max-width: 800px; + padding: 20px; + margin: auto; +} + +header { + margin-top: 40px; + margin-bottom: 80px; + text-align: center; +} + +section { + margin-top: 40px; + margin-bottom: 40px; +} + +section h2 { + text-align: center; +} + +section h3 .date { + font-size: medium; + color: dimgray; +} + +section .description { + padding: 10px; + list-style-position: inside; +} + +footer { + text-align: center; +} diff --git a/chaosevents.py b/chaosevents.py new file mode 100755 index 0000000..8fa5bbd --- /dev/null +++ b/chaosevents.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 + +import arrow +from ics import Calendar +from jinja2 import Environment, FileSystemLoader, select_autoescape +from markdown2 import Markdown +from pathlib import Path +import re +import requests +import sys + +basepath = Path(__file__).resolve().parent + +env = Environment( + loader=FileSystemLoader(basepath / "templates"), + autoescape=select_autoescape() +) + +def render_markdown(text): + pattern = re.compile( + r""" + \b + ( + (?:https?://|(?\s"']* # rest of url + (? 1: + out_path = Path(sys.argv[1]) + + out_path.mkdir(exist_ok=True) + + main(ics_url, out_path) + +if __name__ == "__main__": + cli() diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..fa7d291 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1686501370, + "narHash": "sha256-G0WuM9fqTPRc2URKP9Lgi5nhZMqsfHGrdEbrLvAPJcg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "75a5ebf473cd60148ba9aec0d219f72e5cf52519", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e60ea2c --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + outputs = { self, nixpkgs, ... }: { + packages.x86_64-linux = let + pkgs = import nixpkgs { + system = "x86_64-linux"; + }; + in { + chaosevents = pkgs.python311Packages.buildPythonPackage rec { + pname = "chaosevents"; + version = "0.0.1"; + + src = ./.; + + format = "pyproject"; + + buildInputs = [ pkgs.python311Packages.hatchling ]; + propagatedBuildInputs = with pkgs.python311Packages; [ attrs ics jinja2 markdown2 requests ]; + + pythonImportsCheck = [ "chaosevents" ]; + }; + default = self.packages.x86_64-linux.chaosevents; + }; + + apps.x86_64-linux = { + chaosevents = { + type = "app"; + program = self.packages.x86_64-linux.chaosevents + "/bin/chaosevents"; + }; + default = self.apps.x86_64-linux.chaosevents; + }; + + hydraJobs = { + inherit (self) + packages; + }; + }; +} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d141df3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,34 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "chaosevents" +version = "0.0.1" +authors = [ + { name="clerie", email="hallo@clerie.de" }, +] +description = "" +readme = "README.md" +requires-python = ">=3.11" + +dependencies = [ + "ics", + "jinja2", + "markdown2", + "requests", +] + +[project.scripts] +chaosevents = "chaosevents:cli" + +[project.urls] +"Source" = "https://git.clerie.de/clerie/chaosevents" + +[tool.hatch.build] +include = [ + "*.py", + "assets", + "templates", +] + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..b21a0ab --- /dev/null +++ b/templates/index.html @@ -0,0 +1,43 @@ + + + + Upcoming Chaos Events + + + +
+
+

Chaos Events

+
+ Add to calendar | Event missing? +
+
+ {% if currentevents %} +
+

Current

+
+ {% for event in currentevents %} +
+

{{ event.name }} {{ event.begin.format("YYYY-MM-DD") }} - {{ event.end.shift(seconds=-1).format("YYYY-MM-DD") }}

+
+ {{ event.description_rendered|safe }} +
+
+ {% endfor %} + {% endif %} +
+

Upcoming

+
+ {% for event in upcomingevents %} +
+

{{ event.name }} {{ event.begin.format("YYYY-MM-DD") }} - {{ event.end.shift(seconds=-1).format("YYYY-MM-DD") }}

+
+ {{ event.description_rendered|safe }} +
+
+ {% endfor %} + +
+