PoshCode Logo PowerShell Code Repository

ImaginaryFriendFeed (modification of post by view diff)
View followups from Joel Bennett | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1109"></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.

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

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