Skip to content

Commit

Permalink
add patreon feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
tejing1 committed Dec 6, 2024
1 parent 5a36973 commit 863386e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions homeConfigurations/tejing/news/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ in
# Enable my sfeed module
my.sfeed.enable = true;

# Fix a bug related to IFS in sfeed_update
my.sfeed.package = pkgs.sfeed.overrideAttrs (old: { patches = (old.patches or []) ++ [ ./fix_IFS.patch ]; });

# Pass useful args through to submodule config
my.sfeed.rc._module.args = { inherit pkgs my; };
my.sfeed.rc.imports = [
Expand Down
16 changes: 16 additions & 0 deletions homeConfigurations/tejing/news/fix_IFS.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/sfeed_update b/sfeed_update
index bc74470..4d4d476 100755
--- a/sfeed_update
+++ b/sfeed_update
@@ -239,10 +239,9 @@ main() {
# process a single feed.
# parameters are: config, tmpdir, name, feedurl, basesiteurl, encoding
if [ "${SFEED_UPDATE_CHILD}" = "1" ]; then
- IFS="" # "\037"
[ "$1" = "" ] && exit 0 # must have an argument set
printf '%s\n' "$1" | \
- while read -r _config _tmpdir _name _feedurl _basesiteurl _encoding; do
+ while IFS="" read -r _config _tmpdir _name _feedurl _basesiteurl _encoding; do
loadconfig "${_config}"
sfeedtmpdir="${_tmpdir}"
_feed "${_name}" "${_feedurl}" "${_basesiteurl}" "${_encoding}"
29 changes: 29 additions & 0 deletions homeConfigurations/tejing/news/rc.public.nix
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,33 @@ in
[ .timestamp, .title, .link, "", "", .link, "", .magnet, "" ] | @tsv
''}'';
};

# Fetch from Patreon api. Always pair with patreon parser
fetch.patreon = {
code = ''
local campaign="$(curl -sSLf "$2" | hred '^ script#__NEXT_DATA__ @.textContent' -r | jq '.props.pageProps.bootstrapEnvelope.pageBootstrap.campaign.data.id' -r)"
local cursor=""
local done=""
while [ -z "$done" ];do
exec {fd}< <(
curl -sSf "https://www.patreon.com/api/posts" --url-query "filter[campaign_id]=$campaign" --url-query "sort=-published_at" ''${cursor:+--url-query "page[cursor]=$cursor"} |
jq 'if .meta.pagination.cursors.next == null then "" else .meta.pagination.cursors.next end,.' -rc
)
read -u $fd -r cursor
if [ -z "$cursor" ]; then
done=1
fi
cat <&$fd
exec {fd}<&-
done
'';
};
# Parse Patreon api. Always pair with the patreon fetcher.
parse.patreon = {
code = ''json_parse '' + toFile "patreon.jq" ''
. as $all |
.data[] |
[ .attributes.published_at, .attributes.title, .attributes.url, .attributes.teaser_text, "html", .id, null, null, ([.relationships.user_defined_tags.data[] | select(.type == "post_tag") | .id as $id | $all.included[] | select(.type == "post_tag" and .id == $id) | .attributes.value] | join("|")) ] | @tsv
'';
};
}
Binary file modified homeConfigurations/tejing/news/rc.secret.nix
Binary file not shown.

0 comments on commit 863386e

Please sign in to comment.