Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# Script to migrate a Mastodon-exported following list to micro.blog
# Generate an API key here: https://micro.blog/account/apps
mbapikey=AABBCCDDEEFF001122
# Then go to your Mastodon instances data export, e.g. https://mastodon.social/settings/export
# where you can download your following list in CSV format
# Then simply pipe that list to this script, for example:
# ~/Documents/mastomigrate.sh < ~/Downloads/following_accounts.csv
while read mastodonuser; do
echo -n Bringing ${mastodonuser} to micro.blog…
urlusername=$(echo $mastodonuser|sed -e 's/@/%40/')
if curl -sf "https://micro.blog/discover/search?q=%40${urlusername}" -H "Authorization: $mbapikey" > /dev/null; then
echo "OK! 😀"
else
echo "failed. 🤔"
fi
postdata="username=$urlusername"
contentlength=$(echo -n "$postdata" | wc -c | awk '{print $1}')
echo -n Following ${mastodonuser}
if curl -sf 'https://micro.blog/users/follow' -XPOST -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H "Content-Length: $contentlength" -H "Authorization: $mbapikey" --data "$postdata" > /dev/null ; then
echo "OK! 😀"
else
echo "failed. 🤔"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment