Skip to content

Instantly share code, notes, and snippets.

@mdowst
Last active December 16, 2022 14:13
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 mdowst/a8078c53846ef6bebb34b9c8ea46533d to your computer and use it in GitHub Desktop.
Save mdowst/a8078c53846ef6bebb34b9c8ea46533d to your computer and use it in GitHub Desktop.
Find Twitter Friends on Mastodon
<#
Uses BluebirdPS to get all of the people you follow on Twitter.
Then searches their profile for potential Mastodon usernames.
To setup BluebirdPS: https://github.com/thedavecarroll/BluebirdPS
#>
$TwitterFriends = Get-TwitterFriends
# The property fields to search
$properties = 'Name','Description'
$MastodonFriends = foreach($friend in $TwitterFriends){
foreach($p in $properties){
# Check for username pattern
$username = [regex]::Match($friend.$p, '@([^\s]+)@([^\s]+)\.([0-9a-zA-Z\.]+)')
if($username.Success){
$friend | Select-Object -Property UserName, Name, @{l='Mastodon';e={$username.Value}}
}
# Check for link pattern. Convert links to username format
$link = [regex]::Match($friend.$p, '([0-9a-zA-Z\.]+)/@([0-9a-zA-Z\.]+)')
if($link.Success){
$friend | Select-Object -Property UserName, Name,
@{l='Mastodon';e={"$($link.Value.Split('/')[-1])@$($link.Value.Split('/')[0])"}}
}
}
}
$MastodonFriends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment