run dayli

This commit is contained in:
Jan Andrle 2024-08-29 20:02:13 +02:00
parent 08c9c9ebd6
commit 7d3ca5300a
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
4 changed files with 20 additions and 12 deletions

View File

@ -2,7 +2,7 @@ name: Update menicka
on: on:
workflow_dispatch: workflow_dispatch:
schedule: schedule:
- cron: '0 9 * * 1' # every monday at 9:00 - cron: '0 9 * * *' # every day at 9:00
jobs: jobs:
update-rss: update-rss:

24
cli.mjs
View File

@ -1,33 +1,41 @@
#!/usr/bin/env -S npx nodejsscript #!/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 */ /* 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 { version, description }= s.cat("package.json").xargs(JSON.parse);
const today= [ 6, 0, 1, 2, 3, 4, 5 ][new Date().getDay()];
$.api() $.api()
.version(version) .version(version)
.describe(description) .describe(description)
.command("pull", "Update article list") .command("pull", "Update article list")
.option("--git", "Update git repository") .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`; if(is_git) s.run`git pull --rebase`;
const menicka= await Promise.allSettled([ menickoCukrovarka(), menickoGlobus(), menickoMamafoodbistro() ]) const menicka= await Promise.allSettled([ menickoCukrovarka(), menickoGlobus(), menickoMamafoodbistro() ])
.then(results=> results.filter(p=> p.status!=="rejected").map(p=> p.value)); .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" ]; const days= [ "pondělí", "úterý", "středa", "čtvrtek", "pátek", "sobota", "neděle" ];
let out= description+"\n\n"; const out_head= description+"\n\n" + days.map((v)=> `[${v}](#${v})`).join(" · "); // anchors for days
out+= days.map((v)=> `[${v}](#${v})`).join(" · "); // anchors for days let out= "";
for(const day of days){ // menicka for(let i= today; i < days.length; i++){ // menicka
const day= days[i];
out+= `\n\n## ${day}\n`; out+= `\n\n## ${day}\n`;
out+= menicka.map(dayToMd(day)).join("\n"); out+= menicka.map(dayToMd(day)).join("\n");
} }
const gen= [ "<!-- generated -->", "<!-- /generated -->" ]; const gen= [ "<!-- generated -->", "<!-- /generated -->" ];
const target= "README.md"; const target= "README.md";
const readme= s.cat(target); 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= [ out= [
readme.slice(0, readme.indexOf(gen[0])-1), readme.slice(0, readme_before),
gen[0], out.replace(/(\*)/g, "\\$1"), gen[1], readme_today < 0 ? gen[0]+out_head : readme.slice(readme_before+1, readme_today),
readme.slice(readme.indexOf("\n", readme.indexOf(gen[1]))+1) out.replace(/(\*)/g, "\\$1"),
gen[1], readme.slice(readme.indexOf("\n", readme.indexOf(gen[1]))+1)
].join("\n"); ].join("\n");
s.echo(out).to(target); if(dryRun) echo(out);
else s.echo(out).to(target);
if(is_git) gitCommit([ target ], "pull"); if(is_git) gitCommit([ target ], "pull");
$.exit(0); $.exit(0);

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "menicka-cron", "name": "menicka-cron",
"version": "1.0.3", "version": "1.1.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "menicka-cron", "name": "menicka-cron",
"version": "1.0.3", "version": "1.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"jsdom": "~24.1" "jsdom": "~24.1"

View File

@ -1,6 +1,6 @@
{ {
"name": "menicka-cron", "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.", "description": "Konsolidace obědových meníček pro vybírání obědů v práci.",
"bin": "cli.mjs", "bin": "cli.mjs",
"scripts": { "scripts": {