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
|
sleep 60
|
||||||
'';
|
'';
|
||||||
|
|
||||||
callConvertScripts =
|
reps = mapAttrsToList (name: value:
|
||||||
let
|
let
|
||||||
makeCallLine = recipient:
|
mailAddress = if value.mailAddress != null
|
||||||
map (makeCallLineRecipe recipient.mail) recipient.recipes;
|
then value.mailAddress
|
||||||
makeCallLineRecipe = recipientMail: recipe:
|
else name;
|
||||||
if isNull recipe.content then
|
cronJobs = mapAttrsToList ( jobExpr: jobValue:
|
||||||
"bash ${convertScript} ${recipe.name} ${calibreWithRecipes}/var/news2kindle/recipes ${cfg.mobiPath} ${cfg.fromMail} ${recipientMail}\n"
|
let
|
||||||
else
|
cronExpression = if jobValue.cronExpression != "0 5 * * *"
|
||||||
''
|
then jobValue.cronExpression
|
||||||
mkdir -p /tmp/news2kindle/recipes
|
else jobExpr;
|
||||||
echo "${recipe.content}" > /tmp/news2kindle/recipes/${recipe.name}.recipe
|
in
|
||||||
bash ${convertScript} ${recipe.name} /tmp/news2kindle/recipes/ ${cfg.mobiPath} ${cfg.fromMail} ${recipientMail}
|
jobValue // {cronExpression = cronExpression;}) value.cronJobs;
|
||||||
'';
|
|
||||||
in
|
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 {
|
odfpyNoTest = pkgs.python2Packages.odfpy.overrideAttrs (oldAttrs: rec {
|
||||||
doInstallCheck = false;
|
doInstallCheck = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
calibreWithRecipes = pkgs.calibre.overrideAttrs (oldAttrs: rec {
|
calibreWithRecipes = pkgs.calibre.overrideAttrs (oldAttrs: rec {
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/var/news2kindle/recipes
|
mkdir -p $out/var/news2kindle/recipes
|
||||||
@@ -108,49 +125,7 @@ in
|
|||||||
|
|
||||||
|
|
||||||
recipients = mkOption {
|
recipients = mkOption {
|
||||||
type = with types; listOf (submodule {
|
type = types.attrsOf (types.submodule (import ./recipient-options.nix { inherit config lib; }));
|
||||||
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 = [];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
smtp = {
|
smtp = {
|
||||||
@@ -190,6 +165,6 @@ in
|
|||||||
config = mkIf cfg.enable{
|
config = mkIf cfg.enable{
|
||||||
environment.systemPackages = [pkgs.python27Packages.pyqt5 pkgs.python36Packages.pyqt5 pkgs.mailsend calibreWithRecipes];
|
environment.systemPackages = [pkgs.python27Packages.pyqt5 pkgs.python36Packages.pyqt5 pkgs.mailsend calibreWithRecipes];
|
||||||
services.cron.enable = true;
|
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.enable = true;
|
||||||
services.postfix.extraConfig = "message_size_limit=52428800";
|
services.postfix.extraConfig = "message_size_limit=52428800";
|
||||||
services.news2kindle = {
|
services.news2kindle = {
|
||||||
enable = true;
|
enable = true;
|
||||||
recipients = [
|
recipients = {
|
||||||
{
|
"stubbfel@kindle.com".cronJobs =
|
||||||
mail = "stubbfel@kindle.com";
|
{
|
||||||
recipes = [
|
"0 5 * * *".recipes =
|
||||||
{ name = "heise"; }
|
[
|
||||||
{ name = "taggeschau_de"; }
|
{ name = "heise"; }
|
||||||
{ name = "pro_linux_de"; }
|
{ name = "taggeschau_de"; }
|
||||||
{ name = "scinexx"; }
|
{ name = "zeitde"; }
|
||||||
{ name = "spektrum"; }
|
{ name = "spiegelde"; }
|
||||||
{ name = "netzpolitik"; }
|
{ name = "Postillon";
|
||||||
{ name = "zeitde"; }
|
content = ''
|
||||||
{ name = "spiegelde"; }
|
class BasicUserRecipe1414943033(AutomaticNewsRecipe):
|
||||||
{ name = "lwn_weekly"; }
|
title = u'Der Postillon'
|
||||||
{ name = "linux_magazine"; }
|
oldest_article = 7
|
||||||
{ name = "Postillon";
|
max_articles_per_feed = 100
|
||||||
content = ''
|
auto_cleanup = True
|
||||||
class BasicUserRecipe1414943033(AutomaticNewsRecipe):
|
feeds = [(u'Postilion',
|
||||||
title = u'Der Postillon'
|
u'http://feeds.feedburner.com/blogspot/rkEL')]
|
||||||
oldest_article = 7
|
'';}
|
||||||
max_articles_per_feed = 100
|
];
|
||||||
auto_cleanup = True
|
"0 18 * * 5".recipes =
|
||||||
feeds = [(u'Postilion',
|
[
|
||||||
u'http://feeds.feedburner.com/blogspot/rkEL')]
|
{ name = "pro_linux_de"; }
|
||||||
'';}
|
{ name = "scinexx"; }
|
||||||
{ name = "Stoerungsmelder";
|
{ name = "spektrum"; }
|
||||||
content = ''
|
{ name = "netzpolitik"; }
|
||||||
class BasicUserRecipe1397125629(AutomaticNewsRecipe):
|
{ name = "lwn_weekly"; }
|
||||||
title = u'st\xf6rungsmelder'
|
{ name = "linux_magazine"; }
|
||||||
oldest_article = 7
|
{ name = "Stoerungsmelder";
|
||||||
max_articles_per_feed = 100
|
content = ''
|
||||||
auto_cleanup = True
|
class BasicUserRecipe1397125629(AutomaticNewsRecipe):
|
||||||
feeds = [(u'st\xf6rungsmelder',
|
title = u'st\xf6rungsmelder'
|
||||||
u'http://blog.zeit.de/stoerungsmelder/feed')]
|
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"; }
|
"axelstubbe@kindle.com".cronJobs =
|
||||||
{ name = "berliner_zeitung"; }
|
{
|
||||||
{ name = "MOZ";
|
"0 4 * * *".recipes =
|
||||||
content = ''
|
[
|
||||||
class AdvancedUserRecipe1422191832(BasicNewsRecipe):
|
{ name = "zeitde"; }
|
||||||
title = 'moz'
|
{ name = "spiegelde"; }
|
||||||
oldest_article = 7
|
{ name = "berliner_zeitung"; }
|
||||||
max_articles_per_feed = 100
|
{ name = "MOZ";
|
||||||
auto_cleanup = True
|
content = ''
|
||||||
feeds = [
|
class AdvancedUserRecipe1422191832(BasicNewsRecipe):
|
||||||
('moz-brandenburg', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=1'),
|
title = 'moz'
|
||||||
('moz-uckermark', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=102'),
|
oldest_article = 7
|
||||||
('moz-regionalsport','http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=104'),
|
max_articles_per_feed = 100
|
||||||
('moz-berlin', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=2'),
|
auto_cleanup = True
|
||||||
('moz-sport', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=89'),
|
feeds = [
|
||||||
('moz-kultur','http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=85'),
|
('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