diff --git a/pkgs/feeds/update.sh b/pkgs/feeds/update.sh index b5e217a1..98e9eac9 100755 --- a/pkgs/feeds/update.sh +++ b/pkgs/feeds/update.sh @@ -1,10 +1,24 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash -p curl jq +#!nix-shell -i python3 -p "python3.withPackages (ps: [ ps.feedsearch-crawler ])" -set -xeu -o pipefail +from feedsearch_crawler import search, sort_urls +from feedsearch_crawler.crawler import coerce_url -url="$1" -jsonPath="$2" +import json +import sys +url, jsonPath = sys.argv[1:] -apiQuery="https://feedsearch.dev/api/v1/search?url=$url" -curl -X GET "$apiQuery" | jq '.[0]' > "$jsonPath" +url = coerce_url(url, default_scheme="https") +items = search(url) +items = sort_urls(items) + +# print all results +serialized = [item.serialize() for item in items] +for item in serialized: + print(json.dumps(item, sort_keys=True, indent=2)) + +# save the first result to disk +keep = serialized[0] if serialized else {} +results = json.dumps(keep, sort_keys=True, indent=2) +with open(jsonPath, "w") as out: + out.write(results)