PoshCode Logo PowerShell Code Repository

Compare-TwitterNames.ps1 (modification of post by Steven Murawski view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/871"></script>download | new post

This script will compare the names of the people you follow on Twitter and the people following you. It returns a comparison object consisting of the Twitter name of a subject and a side indicator – “<=” means that you are following a subject who is not following you, “=>” means that you are followed by someone who you are not following.

  1. #This script will compare the names of the people you follow on Twitter
  2. #and the people following you.  It returns a comparison object consisting
  3. #of the Twitter name of a subject and a side indicator -
  4. #"<=" means that you are following a subject who is not following you,
  5. #"=>" means that you are followed by someone who you are not following.
  6.  
  7. function GetTwitterNames([string]$query)
  8. {  
  9.     $wc = new-object System.Net.WebClient
  10.     $wc.Credentials = $script:credential.GetNetworkCredential()
  11.  
  12.     $nbrofpeople = 0
  13.     $page = "&page="
  14.     $names = @()
  15.  
  16.     do
  17.     {
  18.         $url = $query
  19.         if ($nbrofpeople -gt 0)
  20.         {
  21.             $url = $url+$page+($nbrofpeople/100 +1)
  22.         }
  23.  
  24.         [xml]$nameslist = $wc.DownloadString($url)
  25.  
  26.         $names += $nameslist.users.user | select name
  27.  
  28.         $nbrofpeople += 100
  29.     } while ($names.count -eq $nbrofpeople)
  30.  
  31.     return $names
  32. }
  33.  
  34. $twitter = "http://twitter.com/statuses/"
  35. $friends = $twitter + "friends.xml?lite=true"
  36. $followers = $twitter + "followers.xml?lite=true"
  37.  
  38. $credential = Get-Credential
  39.  
  40. $friendslist = GetTwitterNames($friends)
  41. $followerslist = GetTwitterNames($followers)
  42.  
  43. $sync = 0
  44. if ($friendslist.count -gt $followerslist.count)
  45. {
  46.         $sync = ($friendslist.count)/2
  47. }
  48. else
  49. {
  50.         $sync = ($followerslist.count)/2
  51. }
  52.  
  53. $Status = @{Name='Status';Expression={if ($_.sideindicator -like '=>') {'Followed By'} else {'Following'}}}
  54.  
  55. compare-object $friendslist $followerslist -SyncWindow ($sync) -Property name | Select-Object Name, $Status

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me