initial commit

This commit is contained in:
Joeri Exelmans 2025-09-23 11:53:22 +02:00
commit 5f0f9999fc
13 changed files with 1854 additions and 0 deletions

163
.devenv.flake.nix Normal file
View file

@ -0,0 +1,163 @@
{
inputs =
let
version = "1.6.1";
system = "x86_64-linux";
devenv_root = "/home/maestro/repos/icomidal";
devenv_dotfile = ./.devenv;
devenv_dotfile_string = ".devenv";
container_name = null;
devenv_tmpdir = "/run/user/1000";
devenv_runtime = "/run/user/1000/devenv-091177c";
devenv_istesting = false;
devenv_direnvrc_latest_version = 1;
in {
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
pre-commit-hooks.follows = "git-hooks";
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
devenv.url = "github:cachix/devenv?dir=src/modules";
} // (if builtins.pathExists (devenv_dotfile + "/flake.json")
then builtins.fromJSON (builtins.readFile (devenv_dotfile + "/flake.json"))
else { });
outputs = { nixpkgs, ... }@inputs:
let
version = "1.6.1";
system = "x86_64-linux";
devenv_root = "/home/maestro/repos/icomidal";
devenv_dotfile = ./.devenv;
devenv_dotfile_string = ".devenv";
container_name = null;
devenv_tmpdir = "/run/user/1000";
devenv_runtime = "/run/user/1000/devenv-091177c";
devenv_istesting = false;
devenv_direnvrc_latest_version = 1;
devenv =
if builtins.pathExists (devenv_dotfile + "/devenv.json")
then builtins.fromJSON (builtins.readFile (devenv_dotfile + "/devenv.json"))
else { };
getOverlays = inputName: inputAttrs:
map
(overlay:
let
input = inputs.${inputName} or (throw "No such input `${inputName}` while trying to configure overlays.");
in
input.overlays.${overlay} or (throw "Input `${inputName}` has no overlay called `${overlay}`. Supported overlays: ${nixpkgs.lib.concatStringsSep ", " (builtins.attrNames input.overlays)}"))
inputAttrs.overlays or [ ];
overlays = nixpkgs.lib.flatten (nixpkgs.lib.mapAttrsToList getOverlays (devenv.inputs or { }));
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = devenv.allowUnfree or false;
allowBroken = devenv.allowBroken or false;
permittedInsecurePackages = devenv.permittedInsecurePackages or [ ];
};
inherit overlays;
};
lib = pkgs.lib;
importModule = path:
if lib.hasPrefix "./" path
then if lib.hasSuffix ".nix" path
then ./. + (builtins.substring 1 255 path)
else ./. + (builtins.substring 1 255 path) + "/devenv.nix"
else if lib.hasPrefix "../" path
then throw "devenv: ../ is not supported for imports"
else
let
paths = lib.splitString "/" path;
name = builtins.head paths;
input = inputs.${name} or (throw "Unknown input ${name}");
subpath = "/${lib.concatStringsSep "/" (builtins.tail paths)}";
devenvpath = "${input}" + subpath;
devenvdefaultpath = devenvpath + "/devenv.nix";
in
if lib.hasSuffix ".nix" devenvpath
then devenvpath
else if builtins.pathExists devenvdefaultpath
then devenvdefaultpath
else throw (devenvdefaultpath + " file does not exist for input ${name}.");
project = pkgs.lib.evalModules {
specialArgs = inputs // { inherit inputs; };
modules = [
({ config, ... }: {
_module.args.pkgs = pkgs.appendOverlays (config.overlays or [ ]);
})
(inputs.devenv.modules + /top-level.nix)
{
devenv.cliVersion = version;
devenv.root = devenv_root;
devenv.dotfile = devenv_root + "/" + devenv_dotfile_string;
}
(pkgs.lib.optionalAttrs (inputs.devenv.isTmpDir or false) {
devenv.tmpdir = devenv_tmpdir;
devenv.runtime = devenv_runtime;
})
(pkgs.lib.optionalAttrs (inputs.devenv.hasIsTesting or false) {
devenv.isTesting = devenv_istesting;
})
(pkgs.lib.optionalAttrs (container_name != null) {
container.isBuilding = pkgs.lib.mkForce true;
containers.${container_name}.isBuilding = true;
})
({ options, ... }: {
config.devenv = pkgs.lib.optionalAttrs (builtins.hasAttr "direnvrcLatestVersion" options.devenv) {
direnvrcLatestVersion = devenv_direnvrc_latest_version;
};
})
] ++ (map importModule (devenv.imports or [ ])) ++ [
(if builtins.pathExists ./devenv.nix then ./devenv.nix else { })
(devenv.devenv or { })
(if builtins.pathExists ./devenv.local.nix then ./devenv.local.nix else { })
(if builtins.pathExists (devenv_dotfile + "/cli-options.nix") then import (devenv_dotfile + "/cli-options.nix") else { })
];
};
config = project.config;
options = pkgs.nixosOptionsDoc {
options = builtins.removeAttrs project.options [ "_module" ];
warningsAreErrors = false;
# Unpack Nix types, e.g. literalExpression, mDoc.
transformOptions =
let isDocType = v: builtins.elem v [ "literalDocBook" "literalExpression" "literalMD" "mdDoc" ];
in lib.attrsets.mapAttrs (_: v:
if v ? _type && isDocType v._type then
v.text
else if v ? _type && v._type == "derivation" then
v.name
else
v
);
};
build = options: config:
lib.concatMapAttrs
(name: option:
if builtins.hasAttr "type" option then
if option.type.name == "output" || option.type.name == "outputOf" then {
${name} = config.${name};
} else { }
else
let v = build option config.${name};
in if v != { } then {
${name} = v;
} else { }
)
options;
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
in
{
devShell = lib.genAttrs systems (system: config.shell);
packages = lib.genAttrs systems (system: {
optionsJSON = options.optionsJSON;
# deprecated
inherit (config) info procfileScript procfileEnv procfile;
ci = config.ciDerivation;
});
devenv = config;
build = build project.options project.config;
};
}

1
.devenv/devenv.json Normal file
View file

@ -0,0 +1 @@
{"inputs":{"rust-overlay":{"url":"github:oxalica/rust-overlay","inputs":{"nixpkgs":{"follows":"nixpkgs"}}}}}

1
.devenv/flake.json Normal file
View file

@ -0,0 +1 @@
{"rust-overlay":{"url":"github:oxalica/rust-overlay","inputs":{"nixpkgs":{"follows":"nixpkgs"}}}}

0
.devenv/imports.txt Normal file
View file

BIN
.devenv/nix-eval-cache.db Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1559
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

9
Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "icomidal"
version = "0.1.0"
edition = "2024"
[dependencies]
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde = { version = "1.0", features = ["derive"] }
chrono = "0.4"

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1758427187,
"narHash": "sha256-pHpxZ/IyCwoTQPtFIAG2QaxuSm8jWzrzBGjwQZIttJc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "554be6495561ff07b6c724047bdd7e0716aa7b46",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

26
flake.nix Normal file
View file

@ -0,0 +1,26 @@
{
inputs =
{
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, ... }@inputs:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.${system}.default = pkgs.mkShell
{
packages = with pkgs; [
rustc
cargo
];
buildInputs = with pkgs; [
openssl
];
nativeBuildInputs = [ pkgs.pkg-config ];
# env.RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rust}";
};
};
}

67
src/main.rs Normal file
View file

@ -0,0 +1,67 @@
use reqwest::blocking::get;
use serde::Deserialize;
const location_id: &str = "8199"; // Middelheim?
const customer_id: &str = "7622"; // Me?
#[derive(Deserialize)]
struct MenuItem {
SectionName: String,
MenuName: String,
}
#[derive(Deserialize)]
struct Data {
menuPlannerList: Vec<MenuItem>,
}
#[derive(Deserialize)]
struct Response {
data: Data,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let now = chrono::Local::now();
println!("BEGIN:VCALENDAR");
for days_in_future in 0..14 {
let date = now + chrono::Days::new(days_in_future);
// komida API expects local time
let date_komida_fmt = date.format("%Y-%m-%d");
let res: Response = get(format!(
"https://app.growzer.be/MenuPlanner/GetMenuPlanner?locationId={}&stringDate={}&customerId={}",
location_id,
date_komida_fmt,
customer_id,
))?.json()?;
// ical uses UTC
let lunch_starts_at = date.with_time(chrono::NaiveTime::from_hms(11, 30, 00)).unwrap().to_utc();
let lunch_ends_at = date.with_time(chrono::NaiveTime::from_hms(13, 45, 00)).unwrap().to_utc();
for item in res.data.menuPlannerList.iter() {
if item.SectionName.contains("Streetfood")
|| item.SectionName.contains("Dailyfood")
|| item.SectionName.contains("Soep") {
// let d = NaiveDate::parse_from_str(&e.date, "%Y-%m-%d")?;
println!("BEGIN:VEVENT");
println!("SUMMARY:{}", item.MenuName);
println!("DTSTART:{}T{}Z",
lunch_starts_at.format("%Y%m%d"),
lunch_starts_at.format("%H%M%S"),
);
println!("DTEND:{}T{}Z",
lunch_ends_at.format("%Y%m%d"),
lunch_ends_at.format("%H%M%S"),
);
println!("END:VEVENT");
}
}
}
println!("END:VCALENDAR");
Ok(())
}