Guest User

Simple outbox.json (exported from mastodon) Reader

a guest
Jun 24th, 2020
45
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $f = "/path/to/outbox.json"                        # outbox.jsonの絶対パス
  2. $obj = ConvertFrom-Json (Get-Content $f -Encoding utf8)
  3. $TootNumStart  = 0                                 # 表示したいTootの開始連番
  4. $TootNumEnd    = $obj.orderedItems.Count - 1       # 表示したいTootの終了連番
  5. $PublishedFrom = "1970/01/01"                      # 表示したいTootの開始日付
  6. $PublishedTo   = "2099/12/31"                      # 表示したいTootの終了日付
  7. foreach ($TootNum In $TootNumStart..$TootNumEnd) {
  8.     $obj.orderedItems.Item($TootNum).object `
  9.     | ? {[DateTime]($_.published) -GE $PublishedFrom `
  10.     -And [DateTime]($_.published) -LT ([DateTime]$PublishedTo).AddDays(1)} | % {
  11.         write ("Toot#     : {0}" -f $TootNum)
  12.         write ("Url       : {0}" -f $_.url)
  13.         write ("Published : {0:yyyy/MM/dd HH:mm:ss}" -f [DateTime]($_.published))
  14.         [regex]::matches($_.content,"(?:<p>(.+?)</p>)").Captures | % {
  15.             write "Content   : "
  16.         }{
  17.             $content = (($_.Groups[1].Value -replace "<a[^>]*>(.+?)</a>","`$1") `
  18.             -replace "<span[^>]*>(.*?)</span>","`$1") -replace "<br />","`n"
  19.             write "$content`n"
  20.         }
  21.     }
  22. }
RAW Paste Data