feeds: port the update.sh script to use our own feedsearch package instead of the deployed version

This commit is contained in:
colin 2023-01-13 08:58:20 +00:00
parent b6d94c2e08
commit 942c581107

View File

@ -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)