Weekly horoscope: its own page, a Monday e-mail, and one page for every e-mail setting
- The week's sky on the member's own chart (horoscope-api POST /v1/week, astro_engine::week): the planets' aspects to the natal points with the day each is exact, positions, the Moon's signs, lunar phases, stations and sign changes; stored once per chart and week (weekly_skies, migration 0047). - Its text is a 'weekly' analysis written by the summary's (cheap) model when the member opens /heti-horoszkop: one month per page, the newest week first, the waiting animation while it is written. In the menu, and linked from the chart page. - Monday 7:00 e-mail (worker task 'weekly'): only that it is there; on by default for everyone with a chart, members of today too. Its footer opens /ertesitesek?token=…, where the weekly e-mail and every forum e-mail can be set without logging in; the mail client's one-click unsubscribe turns off the weekly one. Also a switch on the page and on the Profile page. - Privacy notice (HU/EN) describes it; ratings, admin labels and the model page know the new kind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -182,6 +182,7 @@ pub fn render(template: &str, locale: &str, payload: &Value) -> Result<Rendered,
|
||||
("purchase_confirmation", _) => purchase_confirmation(lang, payload, url)?,
|
||||
("gift", _) => gift(lang, payload, url)?,
|
||||
("gift_package", _) => gift_package(lang, payload, url)?,
|
||||
("weekly_horoscope", _) => weekly_horoscope(lang, payload, url)?,
|
||||
// The forum is Hungarian only.
|
||||
("forum_reply", _) => forum_reply(payload, url)?,
|
||||
("forum_digest", _) => forum_digest(payload, url)?,
|
||||
@@ -602,6 +603,117 @@ fn name(payload: &Value, field: &str) -> Option<String> {
|
||||
(!name.is_empty()).then(|| name.to_owned())
|
||||
}
|
||||
|
||||
/// Monday's notice that the weekly horoscope is there: only that, the text
|
||||
/// itself is read on the site after logging in.
|
||||
fn weekly_horoscope(lang: Lang, payload: &Value, url: String) -> Result<Content, TemplateError> {
|
||||
let start = field(payload, "week_start")?;
|
||||
let end = field(payload, "week_end")?;
|
||||
let range = week_range(lang, &start, &end).ok_or(TemplateError::MissingField("week_start"))?;
|
||||
let greeting = match (lang, name(payload, "display_name")) {
|
||||
(Lang::Hu, Some(n)) => format!("Szia {n}!"),
|
||||
(Lang::Hu, None) => "Szia!".to_owned(),
|
||||
(Lang::En, Some(n)) => format!("Hi {n},"),
|
||||
(Lang::En, None) => "Hi,".to_owned(),
|
||||
};
|
||||
let unsubscribe_url = field(payload, "unsubscribe_url")?;
|
||||
let unsubscribe_post_url = field(payload, "unsubscribe_post_url")?;
|
||||
Ok(match lang {
|
||||
Lang::Hu => Content {
|
||||
subject: "Itt a heti horoszkópod".into(),
|
||||
preheader: Some(format!("{range}: belépés után a Heti horoszkóp oldalon olvashatod.")),
|
||||
greeting,
|
||||
intro: format!(
|
||||
"Itt a heti horoszkópod {} {range} közötti hétre. Belépés után a Heti horoszkóp oldalon olvashatod.",
|
||||
// "az április 6–12.", "a november 30."
|
||||
if range.starts_with(['a', 'á', 'e', 'é', 'i', 'í', 'o', 'ó', 'ö', 'ő', 'u', 'ú', 'ü', 'ű']) {
|
||||
"az"
|
||||
} else {
|
||||
"a"
|
||||
}
|
||||
),
|
||||
quote: None,
|
||||
points: None,
|
||||
code: None,
|
||||
button: "Megnézem",
|
||||
url,
|
||||
note: "A saját képletedből és a hét égboltjából készül.".into(),
|
||||
reason: Some(
|
||||
"Azért kapod ezt a levelet, mert van képleted a Sorsfonalakon. Ha nem kéred, az alábbi linken vagy a \
|
||||
Profil oldalon kikapcsolhatod."
|
||||
.into(),
|
||||
),
|
||||
unsubscribe: Some(("Leiratkozás, értesítések beállítása", unsubscribe_url)),
|
||||
unsubscribe_post_url: Some(unsubscribe_post_url),
|
||||
},
|
||||
Lang::En => Content {
|
||||
subject: "Your weekly horoscope is here".into(),
|
||||
preheader: Some(format!("{range}: log in to read it on the Weekly horoscope page.")),
|
||||
greeting,
|
||||
intro: format!(
|
||||
"Your weekly horoscope for {range} is here. Log in to read it on the Weekly horoscope page."
|
||||
),
|
||||
quote: None,
|
||||
points: None,
|
||||
code: None,
|
||||
button: "Read it",
|
||||
url,
|
||||
note: "It is written from your own chart and the week's sky.".into(),
|
||||
reason: Some(
|
||||
"You get this e-mail because you have a chart on Sorsfonalak. If you do not want it, turn it off with \
|
||||
the link below or on your Profile page."
|
||||
.into(),
|
||||
),
|
||||
unsubscribe: Some(("Unsubscribe, e-mail settings", unsubscribe_url)),
|
||||
unsubscribe_post_url: Some(unsubscribe_post_url),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// "november 30. – december 6." or "december 7–13." (no year).
|
||||
fn week_range(lang: Lang, start: &str, end: &str) -> Option<String> {
|
||||
let parse = |iso: &str| -> Option<(usize, u32)> {
|
||||
let mut parts = iso.splitn(3, '-').skip(1);
|
||||
let m: usize = parts.next()?.parse().ok()?;
|
||||
let d: u32 = parts.next()?.get(..2)?.parse().ok()?;
|
||||
Some((m.checked_sub(1).filter(|&i| i < 12)?, d))
|
||||
};
|
||||
let ((m1, d1), (m2, d2)) = (parse(start)?, parse(end)?);
|
||||
const HU: [&str; 12] = [
|
||||
"január",
|
||||
"február",
|
||||
"március",
|
||||
"április",
|
||||
"május",
|
||||
"június",
|
||||
"július",
|
||||
"augusztus",
|
||||
"szeptember",
|
||||
"október",
|
||||
"november",
|
||||
"december",
|
||||
];
|
||||
const EN: [&str; 12] = [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
];
|
||||
Some(match (lang, m1 == m2) {
|
||||
(Lang::Hu, true) => format!("{} {d1}–{d2}.", HU[m1]),
|
||||
(Lang::Hu, false) => format!("{} {d1}. – {} {d2}.", HU[m1], HU[m2]),
|
||||
(Lang::En, true) => format!("{d1}–{d2} {}", EN[m1]),
|
||||
(Lang::En, false) => format!("{d1} {} – {d2} {}", EN[m1], EN[m2]),
|
||||
})
|
||||
}
|
||||
|
||||
/// The confirmation of a purchase: what was bought, and that the buyer asked
|
||||
/// for immediate delivery and so gave up the 14-day withdrawal right (the
|
||||
/// confirmation 45/2014. Korm. rendelet 29. § asks for).
|
||||
@@ -1227,6 +1339,31 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weekly_horoscope_only_says_it_is_there() {
|
||||
let payload = json!({
|
||||
"url": "https://sorsfonalak.test/heti-horoszkop",
|
||||
"display_name": "Kata",
|
||||
"week_start": "2026-11-30",
|
||||
"week_end": "2026-12-06",
|
||||
"unsubscribe_url": "https://sorsfonalak.test/ertesitesek?token=abc",
|
||||
"unsubscribe_post_url": "https://sorsfonalak.test/api/v1/public/weekly/unsubscribe?token=abc",
|
||||
});
|
||||
let hu = render("weekly_horoscope", "hu", &payload).unwrap();
|
||||
assert_eq!(hu.subject, "Itt a heti horoszkópod");
|
||||
assert!(hu.text.contains("a november 30. – december 6. közötti hétre"), "{}", hu.text);
|
||||
assert!(
|
||||
hu.text.contains("Leiratkozás, értesítések beállítása: https://sorsfonalak.test/ertesitesek?token=abc")
|
||||
);
|
||||
assert!(hu.html.contains(r#"href="https://sorsfonalak.test/heti-horoszkop""#));
|
||||
assert!(hu.unsubscribe_post_url.is_some());
|
||||
let mut same_month = payload.clone();
|
||||
same_month["week_start"] = json!("2026-12-07");
|
||||
same_month["week_end"] = json!("2026-12-13");
|
||||
let en = render("weekly_horoscope", "en", &same_month).unwrap();
|
||||
assert!(en.text.contains("for 7–13 December is here"), "{}", en.text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn waitlist_confirmation_has_the_leave_link() {
|
||||
let hu = render("waitlist_joined", "hu", &invitation_payload()).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user