Created
February 6, 2026 15:53
-
-
Save andygeorge/32e469099f380e79fef53f457ccc151e to your computer and use it in GitHub Desktop.
HackerNews to Karakeep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/sh | |
| KARAKEEP_URL=https://karakeep.example.com | |
| KARAKEEP_API_TOKEN=YOUR_TOKEN | |
| MAX_LINKS=100 | |
| # Help function | |
| show_help() { | |
| echo "Usage: $0 [options]" | |
| echo "Options:" | |
| echo " -n, --number NUMBER Number of top links to process (default: 100)" | |
| echo " -h, --help Show this help message" | |
| exit 1 | |
| } | |
| # Parse command line arguments | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| -n|--number) | |
| if [[ $2 =~ ^[0-9]+$ ]]; then | |
| MAX_LINKS=$2 | |
| shift 2 | |
| else | |
| echo "Error: Number of links must be a positive integer" | |
| exit 1 | |
| fi | |
| ;; | |
| -h|--help) | |
| show_help | |
| ;; | |
| *) | |
| echo "Unknown option: $1" | |
| show_help | |
| ;; | |
| esac | |
| done | |
| # Create a temporary file | |
| TMP_FILE=$(mktemp) | |
| trap "rm -f $TMP_FILE" EXIT | |
| echo "Fetching Hacker News top stories..." | |
| # Get the top story IDs | |
| TOP_IDS=$(curl -s "https://hacker-news.firebaseio.com/v0/topstories.json" | jq -r '.[0:'"$MAX_LINKS"'][]') | |
| count=0 | |
| for id in $TOP_IDS; do | |
| sleep 2 | |
| # Fetch each story's details | |
| curl -s "https://hacker-news.firebaseio.com/v0/item/$id.json" > "$TMP_FILE" | |
| # Extract the title and URL | |
| TITLE=$(jq -r '.title' "$TMP_FILE") | |
| URL=$(jq -r '.url // "https://news.ycombinator.com/item?id='"$id"'"' "$TMP_FILE") | |
| # Submit the link | |
| echo "title: $TITLE, " | |
| echo "url: $URL, " | |
| curl -L "$KARAKEEP_URL/api/v1/bookmarks" \ | |
| -H 'Content-Type: application/json' \ | |
| -H 'Accept: application/json' \ | |
| -H "Authorization: Bearer $KARAKEEP_API_TOKEN" \ | |
| -d "{\"type\": \"link\", \"title\": \"$TITLE\", \"url\": \"$URL\"}" | |
| ((count++)) | |
| echo "Progress: $count/$MAX_LINKS links processed" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment