summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/bureautomation/comic-updater.nix
blob: 5804d66d2a111508e831ff827cce2c09f0527517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{ config, lib, pkgs, buildPythonPackage, ... }:

let
  mq = "192.168.8.11";
  pkg = pkgs.ampel;
in {
  systemd.services.comic-updater = {
    startAt = "daily";
    description = "update our comics";
    after = [ "network-online.target"  ] ++ (lib.optional config.services.mosquitto.enable "mosquitto.service");
    path = with pkgs; [ wget xmlstarlet ];
    wantedBy = [ "multi-user.target"  ];
    serviceConfig = {
      # User = "hass";
      #WorkingDirectory = config.services.home-assistant.configDir;
      WorkingDirectory = "/var/lib/homeassistant-docker";
      ExecStart = pkgs.writeDash "update-comics" ''
          set -euf
          mkdir -p www/
          cd www/
          # poorly drawn lines
          pic=$(wget -O-  http://www.poorlydrawnlines.com/feed/ \
            | xml sel -t -v '/rss/channel/item/content:encoded' \
            | head -n 2 | sed -n 's/.*src="\([^"]\+\)".*/\1/p' )
          wget "$pic" -nc && cp -v "$(basename "$pic")" lines.png

          #pic=$(curl -L xkcd.com 2>/dev/null | grep imgs.xkcd.com | grep title | sed -n 's/.*src="\([^"]\+\)" .*/https:\1/p')
          # xkcd
          pic=$(wget -O- https://xkcd.com/rss.xml \
            | xml sel -t -v '/rss/channel/item/description' \
            | head -n 1 | sed -n 's/.*src="\([^"]\+\)".*/\1/p' )
          wget "$pic" -nc && cp -v "$(basename "$pic")" xkcd.png
        '';
      PrivateTmp = true;
    };
  };
}