2023-01-10 10:53:55 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
2023-01-13 08:58:20 +00:00
|
|
|
#!nix-shell -i python3 -p "python3.withPackages (ps: [ ps.feedsearch-crawler ])"
|
2023-01-10 10:53:55 +00:00
|
|
|
|
2023-01-13 08:58:20 +00:00
|
|
|
from feedsearch_crawler import search, sort_urls
|
|
|
|
from feedsearch_crawler.crawler import coerce_url
|
2023-01-10 10:53:55 +00:00
|
|
|
|
2023-01-13 08:58:20 +00:00
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
url, jsonPath = sys.argv[1:]
|
2023-01-10 10:53:55 +00:00
|
|
|
|
2023-01-13 08:58:20 +00:00
|
|
|
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)
|