Add sunrise/sunset document

This commit is contained in:
Joscha 2025-03-08 23:53:48 +01:00
parent 14b48c3c21
commit a24532d9cc
11 changed files with 277 additions and 2 deletions

View file

@ -18,6 +18,7 @@ rust-embed = { workspace = true }
serde = { workspace = true }
showbits-assets = { workspace = true }
showbits-typst = { workspace = true }
sunrise = { workspace = true }
tokio = { workspace = true, features = ["full"] }
[lints]

View file

@ -5,6 +5,7 @@ pub mod cells;
pub mod chat;
pub mod egg;
pub mod image;
pub mod sunrise;
pub mod text;
pub mod tictactoe;

View file

@ -0,0 +1,38 @@
{
"year": 2025,
"month": 3,
"times": [
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"],
["01:23", "45:67"]
],
"feed": false
}

View file

@ -0,0 +1 @@
../lib

View file

@ -0,0 +1,46 @@
#import "@preview/oxifmt:0.2.1": strfmt
#import "lib/main.typ" as lib;
#show: it => lib.init(it)
#let data = json("data.json")
#let date = datetime(year: data.year, month: data.month, day: 1)
#let month_length = 32 - (date + duration(days: 31)).day()
#let head(name) = text(size: 32pt, name)
#let empty = box()
#let day(content) = box(
width: 100%,
height: 100%,
stroke: 2pt + black,
content,
)
#align(center + horizon)[
#set par(spacing: 8pt)
Sonnenauf- und Untergang
#strfmt("{:04}-{:02}", date.year(), date.month())
#set par(leading: 5pt)
#grid(
columns: (50pt,) * 7,
rows: 50pt,
gutter: 4pt,
head[Mo], head[Di], head[Mi], head[Do], head[Fr], head[Sa], head[So],
..for _ in range(date.weekday() - 1) { (empty,) },
..for (i, (sunrise, sunset)) in data.times.enumerate() {
(
day[
#strfmt("{:02}", i + 1) \
#sunrise \
#sunset
],
)
},
)
]
#if data.feed {
lib.feed
}

View file

@ -0,0 +1,57 @@
use axum::{Form, extract::State};
use jiff::{Timestamp, ToSpan, Zoned, civil};
use serde::{Deserialize, Serialize};
use crate::server::{Server, somehow};
#[derive(Serialize)]
struct Data {
year: i16,
month: i8,
times: Vec<(String, String)>,
feed: bool,
}
#[derive(Deserialize)]
pub struct FormData {
pub latitude: f64,
pub longitude: f64,
pub year: Option<i16>,
pub month: Option<i8>,
pub feed: Option<bool>,
}
pub async fn post(server: State<Server>, Form(form): Form<FormData>) -> somehow::Result<()> {
let now = Zoned::now().date();
let year = form.year.unwrap_or(now.year());
let month = form.month.unwrap_or(now.month());
let first = civil::Date::new(year, month, 1)?;
let mut times = vec![];
for day in 1..=first.days_in_month() {
let date = first + day.days();
let (rise, set) = sunrise::sunrise_sunset(
form.latitude,
form.longitude,
date.year() as i32,
date.month() as u32,
date.day() as u32,
);
let rise = Timestamp::new(rise, 0)?.strftime("%H:%M").to_string();
let set = Timestamp::new(set, 0)?.strftime("%H:%M").to_string();
times.push((rise, set));
}
let data = Data {
year,
month,
times,
feed: form.feed.unwrap_or(true),
};
let typst = super::typst_with_lib()
.with_json("/data.json", &data)
.with_main_file(include_str!("main.typ"));
server.print_typst(typst).await
}

View file

@ -41,6 +41,7 @@ pub async fn run(tx: mpsc::Sender<Command>, addr: String) -> anyhow::Result<()>
.route("/api/chat", post(documents::chat::post))
.route("/api/egg", post(documents::egg::post))
.route("/api/image", post(documents::image::post))
.route("/api/sunrise", post(documents::sunrise::post))
.route("/api/text", post(documents::text::post))
.route("/api/tictactoe", post(documents::tictactoe::post))
// Rest