Inspired by Jason Strate’s (Blog| Twitter) post “PowerShell: Download List of SQL Server MVPs”, which was inspired by John Samson’s (Blog| Twitter) post “The Best Database Administrators Automate Everything” – which also inspired me. I decided to create a Powershell script to grab my starred items in Google Reader and format them into an HTML Page with links for my Weekly Challenges/Good Reading Posts.
The Set Up
I had an HTML template created for these pages, so I split it into three parts:
- The portion above the Good Reading and Links – I saved this to a text file located at “c:\temp\TopTemplate.txt”
- The Good Reading and Links
- The portion below the Good reading and Links – I saved this to a text file located at “c:\temp\BotTemplate.txt”
I then looked at my public page for Starred Items on Google Reader. Note this script works for any public listing on Google Reader, so I can create a Public Page and change the URL in this script and it still works.
The Code
##------------------------## ##--Reader Starred Items--## ##------------------------## $webclient = New-Object system.net.webclient $SourceFile = "c:\temp\Reader.txt" $HTMLPage = "C:\temp\GoodReading.txt" $TopTemplate = "c:\temp\TopTemplate.txt" $BotTemplate = "c:\temp\BotTemplate.txt" $url="http://www.google.com/reader/shared/user/14135896925018987441/state/com.google/starred" $webclient.DownloadFile($url,$SourceFile) #Get the titles with links $itemtitle = Select-String $SourceFile -pattern "h2 class=""item-title""" | % {$_ -replace "<div id=""items""><div class=""item""><h2 class=""item-title""><div class="""">", ""} | % {$_ -replace "</div></h2>", ""} | % {$_ -replace "<div class=""clear""></div></div></div> <div class=""item""><h2 class=""item-title""><div class="""">", ""} | % {$_ -replace "c:\\temp\\Reader\.txt:[0-9]*:", ""} #Get the details with links $iteminfo = Select-String $SourceFile -pattern "<div class=""item-info"">" | % {$_ -replace "c:\\temp\\Reader\.txt:[0-9]*:<div class=""item-info"">", ""} | % {$_ -replace "</div>", ""} $i=0 $FinalContent = " " foreach ($t in $itemtitle) {$FinalContent= $FinalContent +"<li>"+ $itemtitle[$i] + " " + $iteminfo[$i]+"</li>" + "`r`n " $i++} $FinalContent = "<p><strong>Good Reading from the Week</strong>:</p>" + "`r`n" + "<ul>" + "`r`n" + $FinalContent + "`r`n" + "</ul>" $TopTemp = Get-Content $TopTemplate $BotTemp = Get-Content $BotTemplate $FinalContent = $TopTemp + $FinalContent + $BotTemp Set-Content $HTMLPage $FinalContent invoke-item $HTMLPage
When the script completes, I simply update a couple of statuses and change the photo and it’s good to go!