Skip to content

Instantly share code, notes, and snippets.

@przemoc
Created December 3, 2023 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save przemoc/53b1bfa693181386783754db53edc9da to your computer and use it in GitHub Desktop.
Save przemoc/53b1bfa693181386783754db53edc9da to your computer and use it in GitHub Desktop.
Import GitHub stars to linkding

How to import GitHub stars to linkding

Lame-but-worked-for-me^TM approach to add your GitHub stars to your linkding instance.

Prerequisites

Instructions

Install linkding-cli and github-stars-backup if you haven't already. Create GitHub token for starring if you don't have such. Create linkding-cli config file (assuming ~/.config/linkding.json here) if you don't have such.

Use github-stars-backup.py to dump your stars, e.g.:

export GITHUB_ACCESS_TOKEN=YOUR_GH_TOKEN_FOR_STARRING
github-stars-backup.py YOUR_GH_USERNAME stars-backup.json

Convert obtained JSON into simplistic TXT file (user/project: description per line) that will be fed later into simple shell script. I used sed and jq for that.

cat stars-backup.json | \
    sed '1s,{,[,;$s,},],;s,"[^"]*": {,{,' | jq -r '.[] | (.name + ": " + .description)' \
    >stars-backup.txt

Create executable stars-txt-to-linkding.sh:

#!/bin/sh

set -e

while IFS=$(printf "\n") read -r LINE; do
    PROJ=${LINE%%:*}
    DESC=${LINE#*: }
    echo "$PROJ"
    linkding -c ~/.config/linkding.json bookmarks create --tags github -t "GitHub - $PROJ: $DESC" "https://github.com/$PROJ"
    echo "$PROJ" >>DONE
done

Now run:

./stars-json-to-txt.sh <stars-backup.txt

Patiently wait for all GitHub stars to be added to linkding with github tag. It took me ~2s per star.

You may want to confirm that number of lines in DONE file is the same as in input TXT file.

wc -l stars-backup.txt DONE

Comments

After running stars-json-to-txt.sh I realized that TXT file format could be simpler (user/project per line). It seems that bookmarks added via linkding-cli still fetch URL information (title, description), so there is no true need to construct title on your own.

Both PyGithub and aiolinkding are Python modules, so naturally better solution could be created utilizing them directly. I didn't want to spend more time on this as it was one-time operation for me.

If you have created or are aware of more robust solution for importing GitHub stars to linkding, then please leave a comment about it! I won't need it, but maybe someone else searching for quick solution will benefit from it.

(Why? I'm moving away from GitHub Stars. They were always nothing more than bookmarks in my case.)

@przemoc
Copy link
Author

przemoc commented Dec 3, 2023

As a bonus, oneliner javascript for browser's Developer Tools Console (tested on Edge) to unstar projects currently visible on page https://github.com/YOUR_GH_USERNAME?tab=stars:

$$('button[aria-label="Unstar this repository"]').forEach((el) => el.click())

Refreshing page and running it repeatedly will allow you to quickly get rid of all stars.
DO NOT DO IT IF YOU DON'T HAVE BACKUP OF YOUR STARS!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment