PoshCode Logo PowerShell Code Repository

ImaginaryFriendFeed (modification of post by Joel Bennett view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1110"></script>download | new post

For FriendFeed users: get any twitter friends who aren’t on FriendFeed, and make imaginary versions of them, complete with avatars.

PLEASE NOTICE THIS HAS A LOT OF DEPENDENCIES.

ImaginaryFriends aren’t available (yet?) in the FriendFeed API, so we have to automate them using WatiN, so you’ll need the WatiN script module from PoshCode, plus the actual Watin 2 binaries.

To fully automate it, you’ll also need the HttpRest script module and the MindTouch Dream dll’s that go with that.

Once you have all that, make sure you change the nickname…

  1. #.SYNOPSIS
  2. #  A few functions for working with FriendFeed and Twitter
  3. #.DESCRIPTION
  4. #  Allows you to copy your users from Twitter to imaginary FriendFeed users...
  5. #.EXAMPLE
  6. # ## Get any twitter friends who aren't on friendfeed
  7. # ## Make sure you use FriendFeed's built in "add all your twitter friends" first
  8. # $twits = Get-TwitterFriends `
  9. #         -Nickname jaykul
  10. #         -Exclude $(Get-FriendFeedFriends jaykul | select -expand twitter)
  11. #
  12. # ## YOU MIGHT want to remove people who aren't updating, while you're messing around ...
  13. # $threshold = (Get-Date).AddDays(-14)
  14. # $twits = $twits | Where { $_.protected -or ([DateTime]::ParseExact($_.status.created_at, "ddd MMM dd HH:mm:ss +0000 yyyy", $Null) -gt $threshold) }
  15. #
  16. # ## Add them to friend feed
  17. # foreach($twit in $twits) {
  18. #    New-ImaginaryFriend $twit.name @{twitter=$twit.screen_name} $twit.profile_image_url
  19. # }
  20.  
  21. function New-ImaginaryFriend {
  22. ##.Note
  23. ##    DEPENDS on the WatiN module in http://poshcode.org/1108
  24. ##.Synopsis
  25. ##    Creates a new "Imaginary Friend" on friendfeed by automating your browser
  26. ##.Example
  27. ##    New-ImaginaryFriend PoshCode @{Twitter="PoshCode"} http://poshcode.org/PoshCode.png
  28. ##
  29. [CmdletBinding()]
  30. PARAM($name,[hashtable]$services,$avatar)
  31. ## BEGIN ...
  32.    if($global:ie -is [WatiN.Core.IE]) {
  33.       New-Watin "http`://friendfeed.com/settings/imaginary"
  34.       while( $ie.Url -ne "http`://friendfeed.com/settings/imaginary" ) {
  35.          Set-WatinUrl "http`://friendfeed.com/settings/imaginary"
  36.          Read-Host "Press Enter after you have logged into FriendFeed"
  37.       }
  38.    }
  39. ## TEST/Validate
  40.    Set-WatinUrl http`://friendfeed.com/settings/imaginary
  41.    if($ie.Url -ne "http`://friendfeed.com/settings/imaginary" ) {
  42.       throw "You are not authenticated to FriendFeed. Please log in and try again"
  43.    }
  44.  
  45. ## PROCESS
  46.    Find-Button value "Create imaginary friend" | % { $_.Click() }
  47.    Find-TextField name name | % { $_.TypeText( $name ) }
  48.    (Find-Form action "/a/createimaginary").Buttons | % { $_.click() }
  49.    
  50.    $null = $ie.url -match "http`://friendfeed.com/([^/]*)/services";
  51.    $ffid = $matches[1]
  52.    # Write-Output $ffid
  53.    
  54.    foreach($service in $services.GetEnumerator()) {
  55.       Write-Verbose "$($service.Key): $($service.Value)"
  56.       Find-Link service $service.Key | % { $_.Click() }
  57.       $form = Find-Form action "/a/configureservice"
  58.       @($form.TextFields)[0].TypeText( $service.Value )
  59.       @($form.Buttons)[0].click();
  60.    }
  61.    
  62.    if($avatar) {
  63.       Set-WatinUrl "http`://friendfeed.com/$ffid"
  64.       $avatarFile = Get-WebFile $avatar ([uri]$avatar).segments[-1]
  65.       Write-Verbose "Downloaded? $($avatarFile.FullName)"
  66.       Start-Sleep -milli 500
  67.       Find-Link innertext "Change picture" | %{ $_.Click() }
  68.       Find-FileUpload id pictureupload | % { $_.Set( $avatarFile.FullName ) }
  69.       (Find-Form action "/a/changepicture").Buttons | % { $_.click() }
  70.       Start-Sleep -milli 500
  71.       Remove-Item $avatarFile
  72.    }
  73. }
  74.  
  75.  
  76. ## DEPENDS on the HttpRest module in http://poshcode.org/1107
  77. Function Get-FriendFeedFriends {
  78. Param([string]$UserName,[string[]]$Exclude)
  79.    $friendNames = Get-WebPageText "http`://friendfeed.com/api/user/$username/profile" //user/subscription/nickname @{format="xml";include="subscriptions"} |
  80.                   Where {$Exclude -notcontains $_ }
  81.  
  82.    ForEach($incoming in (Get-WebPageContent "http`://friendfeed.com/api/profiles" //profiles/profile @{ format="xml"; nickname=$($friendNames -join ",") })) {
  83.       $output = Select -Input $incoming Name, NickName |
  84.       Add-Member noteproperty Lists @($incoming.SelectNodes("//list/nickname").InnerText) -Passthru |
  85.       Add-Member noteproperty Rooms @($incoming.SelectNodes("//room/nickname").InnerText) -Passthru
  86.       ForEach($service in $incoming.service) {
  87.          if(!$output."$($service.id)") {
  88.             if($service.username) {
  89.                Add-Member -input $output noteproperty $service.id $service.username
  90.             } else {
  91.                Add-Member -input $output noteproperty $service.id $service.profileUrl
  92.             }
  93.          } else {
  94.             if($service.username) {
  95.                $output."$($service.id)" = @($output."$($service.id)") + $service.username
  96.             } else {
  97.                $output."$($service.id)" = @($output."$($service.id)") + $service.profileUrl
  98.             }
  99.          }
  100.       }
  101.       $output
  102.    }
  103. }
  104.  
  105. ## DEPENDS on the HttpRest module in http://poshcode.org/1107
  106. function Get-TwitterFriends {
  107. Param($UserName, [string[]]$Exclude)
  108.    $page = 0; $tweeters = @()
  109.    do {
  110.       $tweeters = Get-WebPageContent "http`://twitter.com/statuses/friends.xml" //users/user @{page=(++$page); screen_name=$UserName} |
  111.                   Where {$Exclude -notcontains $_.screen_name }
  112.       Write-Output $tweeters
  113.    } while($tweeters)
  114. }

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