init-feed: lift out of pkgs/ and into scripts/ where its easier to invoke

This commit is contained in:
2024-06-24 17:04:11 +00:00
parent cbc2ba02a4
commit a0dfdb5125
2 changed files with 21 additions and 22 deletions

View File

@@ -44,26 +44,4 @@ lib.makeScope newScope (self: with self; {
pyPkgs = [ "feedsearch-crawler" ];
srcPath = "update.py";
};
init-feed = writeShellScript
"init-feed"
''
# this is the `nix run '.#init-feed' <url>` script`
sources_dir=modules/data/feeds/sources
# prettify the URL, by default
name=$( \
echo "$1" \
| sed 's|^https://||' \
| sed 's|^http://||' \
| sed 's|^www\.||' \
| sed 's|/+$||' \
)
json_path="$sources_dir/$name/default.json"
# the name could have slashes in it, so we want to mkdir -p that
# but in a way where the least could go wrong.
pushd "$sources_dir"; mkdir -p "$name"; popd
${update-feed}/bin/update.py "$name" "$json_path"
cat "$json_path"
'';
})

21
scripts/init-feed Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p feeds.update-feed -p gnused
sources_dir=modules/data/feeds/sources
# prettify the URL, by default
name=$( \
echo "$1" \
| sed 's|^https://||' \
| sed 's|^http://||' \
| sed 's|^www\.||' \
| sed 's|/+$||' \
)
json_path="$sources_dir/$name/default.json"
# the name could have slashes in it, so we want to mkdir -p that
# but in a way where the least could go wrong.
pushd "$sources_dir"; mkdir -p "$name"; popd
# update.py: from `feeds.update-feed` (TODO: rename the binary!)
update.py "$name" "$json_path"
cat "$json_path"