Last active
November 1, 2016 01:16
-
-
Save Windos/8f1fb5b40af32ada00136ca4e0a60434 to your computer and use it in GitHub Desktop.
Lunch hours effort in downloading then converting PuTTY themes into a standard JSON format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ThemeLists = 'http://putty.org.ru/themes/index.html', 'http://putty.org.ru/themes/page2.html', 'http://putty.org.ru/themes/page3.html', 'http://putty.org.ru/themes/page4.html', 'http://putty.org.ru/themes/page5.html' | |
foreach ($Uri in $ThemeLists) | |
{ | |
$Content = Invoke-WebRequest -Uri $Uri | |
$List = $Content.ParsedHtml.getElementsByTagName('ol') | |
$Links = $List[0] | foreach {$_.getElementsByTagName('a') | where {$_.textContent -ne $null} } | |
foreach ($Link in $Links) | |
{ | |
$Url = 'http://putty.org.ru/' + $Link.pathname | |
$Name = $Link.textContent | |
$FileName = $Name -replace ' ', '-' | |
$WebContent = Invoke-WebRequest -Uri $Url | |
$Code = ($WebContent.ParsedHtml.getElementsByTagName('pre'))[0].innerText | |
$Obj = New-Object -TypeName PSCustomObject -Property @{ | |
Name = $Name | |
Url = $Url | |
Colors = [ordered]@{} | |
} | |
foreach ($Line in $Code -split "`r`n") | |
{ | |
if ($Line -like '"*') | |
{ | |
$SplitLine = $Line.Replace('"', '').Split('=') | |
$Obj.Colors.Add($SplitLine[0], $SplitLine[1]) | |
} | |
} | |
$json = $Obj | Select Name, Url, Colors | ConvertTo-Json | |
$json -replace ' ', ' ' -replace ' ', ' ' -replace ' ', ' ' | Out-File -FilePath "d:\themes\$FileName.json" -NoNewline -Encoding utf8 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment