Skip to content

Instantly share code, notes, and snippets.

@pmachapman
Created February 8, 2022 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmachapman/0c9d10d754abff6f0fb0abd54131dcb6 to your computer and use it in GitHub Desktop.
Save pmachapman/0c9d10d754abff6f0fb0abd54131dcb6 to your computer and use it in GitHub Desktop.
Parses a JSON file from Creeds.json into HTML
$url = "https://raw.githubusercontent.com/NonlinearFruit/Creeds.json/master/creeds/keachs_catechism.json"
$parts = $url.Split("/")
$index = $parts.count - 1
$filename = $parts.GetValue($index).ToString().Replace("_", "-").Replace(".json", ".html")
$response = Invoke-WebRequest -Uri $url -UseBasicParsing
$creed = $response | ConvertFrom-Json
foreach ($data in $creed.data)
{
"<li id=`"q$($data.Number)`">" | Out-File -FilePath $filename -Append
$question = $data.Question.Replace("'", "&rsquo;")
"`t<strong>$($question)</strong><br>" | Out-File -FilePath $filename -Append
$answer = $data.Answer.Replace("'", "&rsquo;")
"`t$($answer)" | Out-File -FilePath $filename -Append
"`t<div class=`"references`">" | Out-File -FilePath $filename -Append
foreach ($proof in $data.Proofs)
{
$postParams = @{references="$($proof.References)"}
$referencesResponse = Invoke-WebRequest -Uri https://conglomo.azurewebsites.net/sort.php?api=1 -Method POST -Body $postParams
$references = $referencesResponse.Content
"`t`t$($references)" | Out-File -FilePath $filename -Append
}
"`t</div>" | Out-File -FilePath $filename -Append
"</li>" | Out-File -FilePath $filename -Append
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment