Meta: Creating My Bookmarks Page
Description:
As anyone who is into scripting must sometime learn, I need to learn how to use Regex with Powershell. I’m very new at this still so I wanted to start with a task I have to do kind of frequently: Updating my Bookmarks page.
Essentially:
- Add random links to Google Bookmarks while I’m browsing. This is not to be confused with Chrome bookmarks. It is it’s own site/ service (bookmarks.google.com) that I use for professional references and not my dank internet memes.
- PS will download this file in line 6.
- The rest of the script just does find and replace of the strings.
- Once it is done, I just copy the completed to my post in WordPress. Done.
To Resolve:
-
Script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
If (Test-Path "c:\users\$env:username\Downloads\GoogleBookmarks.html") { Remove-Item "c:\users\$env:username\Downloads\GoogleBookmarks.html" } & 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' https://www.google.com/bookmarks/bookmarks.html?hl=en Set-Location -Path "$env:userprofile\Downloads" Start-Sleep -Seconds 6 $File = "$env:userprofile\Downloads\GoogleBookmarks.html" $Find = [regex]::Escape($Find) $Find = '<DT>' $Replace = (Get-Content $File -Raw) -replace '<DT>', '' -Replace '<DL>', '' -Replace '</DL>','' -replace 'ADD_DATE=..................','' | Add-Content -Path "$File.tmp" -Force Remove-Item -Path $File Rename-Item -Path "$File.tmp" -NewName $File $a = foreach ($line in [System.IO.File]::ReadLines($file)) { If ( $line -cmatch '^<A HREF' ) { [regex]$pattern = '>' $pattern.replace($line,'>', 1) } Else { $line } } $a | Out-File '.\Completed.html'
-
Source is maintained under gwNetworking
Comments