⚡ run dayli
This commit is contained in:
parent
08c9c9ebd6
commit
7d3ca5300a
@ -2,7 +2,7 @@ name: Update menicka
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 9 * * 1' # every monday at 9:00
|
||||
- cron: '0 9 * * *' # every day at 9:00
|
||||
|
||||
jobs:
|
||||
update-rss:
|
||||
|
24
cli.mjs
24
cli.mjs
@ -1,33 +1,41 @@
|
||||
#!/usr/bin/env -S npx nodejsscript
|
||||
/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */
|
||||
const { version, description }= s.cat("package.json").xargs(JSON.parse);
|
||||
const today= [ 6, 0, 1, 2, 3, 4, 5 ][new Date().getDay()];
|
||||
|
||||
$.api()
|
||||
.version(version)
|
||||
.describe(description)
|
||||
.command("pull", "Update article list")
|
||||
.option("--git", "Update git repository")
|
||||
.action(async function pull({ git: is_git= false }){
|
||||
.option("--dry-run", "Dry run")
|
||||
.action(async function pull({ git: is_git= false, ["dry-run"]: dryRun= false, ..._ }= {}){
|
||||
if(dryRun) is_git= false;
|
||||
if(is_git) s.run`git pull --rebase`;
|
||||
|
||||
const menicka= await Promise.allSettled([ menickoCukrovarka(), menickoGlobus(), menickoMamafoodbistro() ])
|
||||
.then(results=> results.filter(p=> p.status!=="rejected").map(p=> p.value));
|
||||
const days= [ "pondělí", "úterý", "středa", "čtvrtek", "pátek", "sobota", "neděle" ];
|
||||
let out= description+"\n\n";
|
||||
out+= days.map((v)=> `[${v}](#${v})`).join(" · "); // anchors for days
|
||||
for(const day of days){ // menicka
|
||||
const out_head= description+"\n\n" + days.map((v)=> `[${v}](#${v})`).join(" · "); // anchors for days
|
||||
let out= "";
|
||||
for(let i= today; i < days.length; i++){ // menicka
|
||||
const day= days[i];
|
||||
out+= `\n\n## ${day}\n`;
|
||||
out+= menicka.map(dayToMd(day)).join("\n");
|
||||
}
|
||||
const gen= [ "<!-- generated -->", "<!-- /generated -->" ];
|
||||
const target= "README.md";
|
||||
const readme= s.cat(target);
|
||||
const readme_before= readme.indexOf(gen[0])-1;
|
||||
const readme_today= today===0 ? -1 : readme.indexOf(`## ${days[today]}`, readme_before)-2;
|
||||
out= [
|
||||
readme.slice(0, readme.indexOf(gen[0])-1),
|
||||
gen[0], out.replace(/(\*)/g, "\\$1"), gen[1],
|
||||
readme.slice(readme.indexOf("\n", readme.indexOf(gen[1]))+1)
|
||||
readme.slice(0, readme_before),
|
||||
readme_today < 0 ? gen[0]+out_head : readme.slice(readme_before+1, readme_today),
|
||||
out.replace(/(\*)/g, "\\$1"),
|
||||
gen[1], readme.slice(readme.indexOf("\n", readme.indexOf(gen[1]))+1)
|
||||
].join("\n");
|
||||
s.echo(out).to(target);
|
||||
if(dryRun) echo(out);
|
||||
else s.echo(out).to(target);
|
||||
|
||||
if(is_git) gitCommit([ target ], "pull");
|
||||
$.exit(0);
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "menicka-cron",
|
||||
"version": "1.0.3",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "menicka-cron",
|
||||
"version": "1.0.3",
|
||||
"version": "1.1.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jsdom": "~24.1"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "menicka-cron",
|
||||
"version": "1.0.3",
|
||||
"version": "1.1.0",
|
||||
"description": "Konsolidace obědových meníček pro vybírání obědů v práci.",
|
||||
"bin": "cli.mjs",
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user