Created
January 8, 2022 23:10
-
-
Save intellectronica/4e5f3363d891a64c42566d104e881977 to your computer and use it in GitHub Desktop.
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
# fill auth token here. see https://github.com/nicolevanderhoeven/shortform-to-readwise#usage for how to get it | |
$authToken = '...' | |
$booksApiUrl = 'https://www.shortform.com/api/books/' | |
$bookSlug = $args[0] | |
$response = Invoke-WebRequest -Uri "$booksApiUrl$bookSlug" -Headers @{ | |
"Authorization" = "Basic $authToken"; | |
"X-Sf-Client" = "11.8.0"; | |
} | |
$data = ($response.Content | Out-String | ConvertFrom-Json).data | |
$title = $data.title + " (Summary)" | |
$author = $data.author + " (Shortform)" | |
$cover = "https:" + $data.cover_image | |
$created = $data.created.ToString("yyyy-MM-dd") | |
$tags = $data.tags | |
$chapters = $data.content | Where-Object -Property content_type -EQ 'chapter' | | |
ForEach-Object { @{ "title" = $_.title; "text" = $_.text } } | |
$chaptersString = ($chapters | ForEach-Object { "`n<h2>" + $_.title + "</h2>`n" + $_.text }) | |
$htmlString = @" | |
<html> | |
<head><title>$title- $author</title></head> | |
<body> | |
$chaptersString | |
</body> | |
</html> | |
"@ | |
Invoke-WebRequest -Uri $cover -OutFile ".\$bookSlug.png" | |
Set-Content -Path ".\$bookSlug.html" -Value $htmlString | |
pandoc --toc -M title=$title -M author=$author -M date=$created -M publisher=Shortform -M cover-image=".\$bookSlug.png" -o ".\$bookSlug-summary.epub" ".\$bookSlug.html" | |
Remove-Item ".\$bookSlug.html" | |
Remove-Item ".\$bookSlug.png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment