# encoding: ascii
# api: powershell
# title: Import-Instapaper
# description: Search and browse to url in an instapaper csv.
# version: 0.1
# type: script
# author: Adminian
# license: CC0
# function: Get-FileName
# x-poshcode-id: 2588
# x-archived: 2016-11-14T08:19:10
# x-published: 2011-03-27T18:24:00
#
#
   #                                           
  # #   #####  #    # # #    # #   ##   #    # 
 #   #  #    # ##  ## # ##   # #  #  #  ##   # 
#     # #    # # ## # # # #  # # #    # # #  # 
####### #    # #    # # #  # # # ###### #  # # 
#     # #    # #    # # #   ## # #    # #   ## 
#     # #####  #    # # #    # # #    # #    # 

## It's a quick little script to search instapaper csv


Function Get-FileName($initialDirectory)
{   
 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
 Out-Null

 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.ShowHelp = $true
 $OpenFileDialog.initialDirectory = $initialDirectory
 $OpenFileDialog.filter = "All files (*.*)| *.*"
 $OpenFileDialog.ShowDialog() | Out-Null
 $OpenFileDialog.filename
}

## Get the CSV File
$fileName = Get-FileName -initialDirectory "~"

$csv = Import-Csv $fileName

## I use this for a broad search or topic search
$search = Read-Host "Search Topic: "
$csv | Where-Object {$_.Title -like "*" + $search + "*"} | ft title

## This is the refined search that will open IE
$search = Read-Host "Open Title: "
$result = $csv | Where-Object {$_.Title -like "*" + $search + "*"}
$ie = New-Object -comobject "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($result.url)
