add configable cronjob expressions
This commit is contained in:
17
module/news2kindle/cronjob-options.nix
Normal file
17
module/news2kindle/cronjob-options.nix
Normal file
@@ -0,0 +1,17 @@
|
||||
{ config, lib }:
|
||||
|
||||
with lib;
|
||||
{
|
||||
options = {
|
||||
cronExpression = mkOption {
|
||||
type = types.str;
|
||||
default = "0 5 * * *";
|
||||
description = '' cron expression, when fetch should started. '';
|
||||
example = "0 5 * * *";
|
||||
};
|
||||
|
||||
recipes = mkOption {
|
||||
type = types.listOf (types.submodule (import ./recipe-options.nix { inherit config lib; }));
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -22,32 +22,49 @@ mailsend -smtp ${cfg.smtp.address} -port ${portString} -from $FROMADDR -to $TOAD
|
||||
sleep 60
|
||||
'';
|
||||
|
||||
callConvertScripts =
|
||||
reps = mapAttrsToList (name: value:
|
||||
let
|
||||
makeCallLine = recipient:
|
||||
map (makeCallLineRecipe recipient.mail) recipient.recipes;
|
||||
makeCallLineRecipe = recipientMail: recipe:
|
||||
if isNull recipe.content then
|
||||
"bash ${convertScript} ${recipe.name} ${calibreWithRecipes}/var/news2kindle/recipes ${cfg.mobiPath} ${cfg.fromMail} ${recipientMail}\n"
|
||||
else
|
||||
''
|
||||
mkdir -p /tmp/news2kindle/recipes
|
||||
echo "${recipe.content}" > /tmp/news2kindle/recipes/${recipe.name}.recipe
|
||||
bash ${convertScript} ${recipe.name} /tmp/news2kindle/recipes/ ${cfg.mobiPath} ${cfg.fromMail} ${recipientMail}
|
||||
'';
|
||||
mailAddress = if value.mailAddress != null
|
||||
then value.mailAddress
|
||||
else name;
|
||||
cronJobs = mapAttrsToList ( jobExpr: jobValue:
|
||||
let
|
||||
cronExpression = if jobValue.cronExpression != "0 5 * * *"
|
||||
then jobValue.cronExpression
|
||||
else jobExpr;
|
||||
in
|
||||
jobValue // {cronExpression = cronExpression;}) value.cronJobs;
|
||||
in
|
||||
concatMap makeCallLine cfg.recipients;
|
||||
value // { mailAddress = name; cronJobs = cronJobs; }
|
||||
) cfg.recipients;
|
||||
|
||||
jobs = concatMap(recipient: concatMap(cronjob:
|
||||
let
|
||||
scriptName = builtins.replaceStrings ["*"] ["star"] (builtins.replaceStrings [" "] ["_"] (builtins.replaceStrings ["@"] [""] "${recipient.mailAddress}-${cronjob.cronExpression}.sh"));
|
||||
scriptlines = concatMapStrings(recipe:
|
||||
if isNull recipe.content then
|
||||
"bash ${convertScript} ${recipe.name} ${calibreWithRecipes}/var/news2kindle/recipes ${cfg.mobiPath} ${recipient.fromMail} ${recipient.mailAddress}\n"
|
||||
else
|
||||
''
|
||||
mkdir -p /tmp/news2kindle/recipes
|
||||
echo "${recipe.content}" > /tmp/news2kindle/recipes/${recipe.name}.recipe
|
||||
bash ${convertScript} ${recipe.name} /tmp/news2kindle/recipes/ ${cfg.mobiPath} ${recipient.fromMail} ${recipient.mailAddress}
|
||||
'' ) cronjob.recipes;
|
||||
script = pkgs.writeText "${scriptName}" ''#!/bin/bash
|
||||
rm -f ${cfg.mobiPath}/*.mobi
|
||||
mkdir -p ${cfg.mobiPath}
|
||||
${scriptlines}
|
||||
'';
|
||||
in
|
||||
["${cronjob.cronExpression} root bash ${script}"]) recipient.cronJobs) reps;
|
||||
|
||||
dailyUpdateScript = pkgs.writeText "dailyUpdates.sh" ''#!/bin/bash
|
||||
rm -f ${cfg.mobiPath}/*.mobi
|
||||
mkdir -p ${cfg.mobiPath}
|
||||
${concatStrings callConvertScripts}
|
||||
'';
|
||||
|
||||
odfpyNoTest = pkgs.python2Packages.odfpy.overrideAttrs (oldAttrs: rec {
|
||||
doInstallCheck = false;
|
||||
});
|
||||
|
||||
|
||||
|
||||
calibreWithRecipes = pkgs.calibre.overrideAttrs (oldAttrs: rec {
|
||||
installPhase = ''
|
||||
mkdir -p $out/var/news2kindle/recipes
|
||||
@@ -108,49 +125,7 @@ in
|
||||
|
||||
|
||||
recipients = mkOption {
|
||||
type = with types; listOf (submodule {
|
||||
options = {
|
||||
mail = mkOption {
|
||||
type = types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
name of recipe
|
||||
'';
|
||||
};
|
||||
recipes = mkOption {
|
||||
type = with types; listOf (submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
name of recipe
|
||||
'';
|
||||
};
|
||||
content = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
content of the recipe file, when its null the use the builtins recipes
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
default = [];
|
||||
example = [ { name = "heise";} { name = "Postillon"; port = ''
|
||||
class BasicUserRecipe1414943033(AutomaticNewsRecipe):
|
||||
title = u'Postillon'
|
||||
oldest_article = 7
|
||||
max_articles_per_feed = 100
|
||||
auto_cleanup = True
|
||||
feeds= [(u'Postilion', u'http://feeds.feedburner.com/blogspot/rkEL')] ''; } ];
|
||||
description = ''
|
||||
List of recipes wich the user wants fetch. If recipe content is not specified the fetcher uses builtins recipes
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
default = [];
|
||||
type = types.attrsOf (types.submodule (import ./recipient-options.nix { inherit config lib; }));
|
||||
};
|
||||
|
||||
smtp = {
|
||||
@@ -190,6 +165,6 @@ in
|
||||
config = mkIf cfg.enable{
|
||||
environment.systemPackages = [pkgs.python27Packages.pyqt5 pkgs.python36Packages.pyqt5 pkgs.mailsend calibreWithRecipes];
|
||||
services.cron.enable = true;
|
||||
services.cron.systemCronJobs = [ "0 5 * * * root bash ${dailyUpdateScript}"];
|
||||
services.cron.systemCronJobs = jobs;
|
||||
};
|
||||
}
|
||||
|
||||
17
module/news2kindle/recipe-options.nix
Normal file
17
module/news2kindle/recipe-options.nix
Normal file
@@ -0,0 +1,17 @@
|
||||
{ config, lib }:
|
||||
|
||||
with lib;
|
||||
{
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
default = null;
|
||||
description = '' name of recipe '';
|
||||
};
|
||||
content = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = '' content of the recipe file, when its null the use the builtins recipes '';
|
||||
};
|
||||
};
|
||||
}
|
||||
30
module/news2kindle/recipient-options.nix
Normal file
30
module/news2kindle/recipient-options.nix
Normal file
@@ -0,0 +1,30 @@
|
||||
{ config, lib }:
|
||||
|
||||
let
|
||||
cfg = config.services.news2kindle;
|
||||
in
|
||||
|
||||
with lib;
|
||||
{
|
||||
options = {
|
||||
mailAddress = mkOption {
|
||||
type = types.str;
|
||||
default = null;
|
||||
description = '' mail address of the recipient '';
|
||||
example = "foo@bar.bla";
|
||||
};
|
||||
|
||||
fromMail = mkOption {
|
||||
example = "foo@bar.bla";
|
||||
default = cfg.fromMail;
|
||||
type = types.str;
|
||||
description = ''
|
||||
Adrees of the sender, please allow this mail in your kindle doc service
|
||||
'';
|
||||
};
|
||||
|
||||
cronJobs = mkOption {
|
||||
type = types.attrsOf (types.submodule (import ./cronjob-options.nix { inherit config lib; }));
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -4,68 +4,73 @@
|
||||
services.postfix.enable = true;
|
||||
services.postfix.extraConfig = "message_size_limit=52428800";
|
||||
services.news2kindle = {
|
||||
enable = true;
|
||||
recipients = [
|
||||
{
|
||||
mail = "stubbfel@kindle.com";
|
||||
recipes = [
|
||||
{ name = "heise"; }
|
||||
{ name = "taggeschau_de"; }
|
||||
{ name = "pro_linux_de"; }
|
||||
{ name = "scinexx"; }
|
||||
{ name = "spektrum"; }
|
||||
{ name = "netzpolitik"; }
|
||||
{ name = "zeitde"; }
|
||||
{ name = "spiegelde"; }
|
||||
{ name = "lwn_weekly"; }
|
||||
{ name = "linux_magazine"; }
|
||||
{ name = "Postillon";
|
||||
content = ''
|
||||
class BasicUserRecipe1414943033(AutomaticNewsRecipe):
|
||||
title = u'Der Postillon'
|
||||
oldest_article = 7
|
||||
max_articles_per_feed = 100
|
||||
auto_cleanup = True
|
||||
feeds = [(u'Postilion',
|
||||
u'http://feeds.feedburner.com/blogspot/rkEL')]
|
||||
'';}
|
||||
{ name = "Stoerungsmelder";
|
||||
content = ''
|
||||
class BasicUserRecipe1397125629(AutomaticNewsRecipe):
|
||||
title = u'st\xf6rungsmelder'
|
||||
oldest_article = 7
|
||||
max_articles_per_feed = 100
|
||||
auto_cleanup = True
|
||||
feeds = [(u'st\xf6rungsmelder',
|
||||
u'http://blog.zeit.de/stoerungsmelder/feed')]
|
||||
'';}
|
||||
];
|
||||
}
|
||||
{
|
||||
mail = "axelstubbe@kindle.com";
|
||||
recipes = [
|
||||
{ name = "zeitde"; }
|
||||
{ name = "spiegelde"; }
|
||||
{ name = "berliner_zeitung"; }
|
||||
{ name = "MOZ";
|
||||
content = ''
|
||||
class AdvancedUserRecipe1422191832(BasicNewsRecipe):
|
||||
title = 'moz'
|
||||
oldest_article = 7
|
||||
max_articles_per_feed = 100
|
||||
auto_cleanup = True
|
||||
feeds = [
|
||||
('moz-brandenburg', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=1'),
|
||||
('moz-uckermark', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=102'),
|
||||
('moz-regionalsport','http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=104'),
|
||||
('moz-berlin', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=2'),
|
||||
('moz-sport', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=89'),
|
||||
('moz-kultur','http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=85'),
|
||||
]
|
||||
'';
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
enable = true;
|
||||
recipients = {
|
||||
"stubbfel@kindle.com".cronJobs =
|
||||
{
|
||||
"0 5 * * *".recipes =
|
||||
[
|
||||
{ name = "heise"; }
|
||||
{ name = "taggeschau_de"; }
|
||||
{ name = "zeitde"; }
|
||||
{ name = "spiegelde"; }
|
||||
{ name = "Postillon";
|
||||
content = ''
|
||||
class BasicUserRecipe1414943033(AutomaticNewsRecipe):
|
||||
title = u'Der Postillon'
|
||||
oldest_article = 7
|
||||
max_articles_per_feed = 100
|
||||
auto_cleanup = True
|
||||
feeds = [(u'Postilion',
|
||||
u'http://feeds.feedburner.com/blogspot/rkEL')]
|
||||
'';}
|
||||
];
|
||||
"0 18 * * 5".recipes =
|
||||
[
|
||||
{ name = "pro_linux_de"; }
|
||||
{ name = "scinexx"; }
|
||||
{ name = "spektrum"; }
|
||||
{ name = "netzpolitik"; }
|
||||
{ name = "lwn_weekly"; }
|
||||
{ name = "linux_magazine"; }
|
||||
{ name = "Stoerungsmelder";
|
||||
content = ''
|
||||
class BasicUserRecipe1397125629(AutomaticNewsRecipe):
|
||||
title = u'st\xf6rungsmelder'
|
||||
oldest_article = 7
|
||||
max_articles_per_feed = 100
|
||||
auto_cleanup = True
|
||||
feeds = [(u'st\xf6rungsmelder',
|
||||
u'http://blog.zeit.de/stoerungsmelder/feed')]
|
||||
'';}
|
||||
];
|
||||
};
|
||||
"axelstubbe@kindle.com".cronJobs =
|
||||
{
|
||||
"0 4 * * *".recipes =
|
||||
[
|
||||
{ name = "zeitde"; }
|
||||
{ name = "spiegelde"; }
|
||||
{ name = "berliner_zeitung"; }
|
||||
{ name = "MOZ";
|
||||
content = ''
|
||||
class AdvancedUserRecipe1422191832(BasicNewsRecipe):
|
||||
title = 'moz'
|
||||
oldest_article = 7
|
||||
max_articles_per_feed = 100
|
||||
auto_cleanup = True
|
||||
feeds = [
|
||||
('moz-brandenburg', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=1'),
|
||||
('moz-uckermark', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=102'),
|
||||
('moz-regionalsport','http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=104'),
|
||||
('moz-berlin', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=2'),
|
||||
('moz-sport', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=89'),
|
||||
('moz-kultur','http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=85'),
|
||||
]
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user