Skip to content

Commit

Permalink
✨ Parse Pocket results; convert from Epoch time
Browse files Browse the repository at this point in the history
  • Loading branch information
brianary committed Sep 27, 2023
1 parent c868ca3 commit 1162c75
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 40 deletions.
36 changes: 36 additions & 0 deletions ConvertFrom-EpochTime.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<#
.SYNOPSIS
Converts an integer Unix (POSIX) time (seconds since Jan 1, 1970) into a DateTime value.
.INPUTS
System.Int32 value converted from date and time value.
.OUTPUTS
System.DateTime value to convert to integer.
.FUNCTIONALITY
Date and time
.LINK
https://en.wikipedia.org/wiki/Unix_time
.LINK
https://stackoverflow.com/a/1860511/54323
.LINK
Get-Date
.EXAMPLE
1556884381 |ConvertFrom-EpochTime.ps1
Friday, May 3, 2019 11:53:01
#>

#Requires -Version 3
[CmdletBinding()][OutputType([int])] Param(
# The Epoch time value to convert to a DateTime.
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][long] $InputObject,
# Indicates the DateTime provided is local, and should be converted to UTC.
[Alias('UTC','Z')][switch] $UniversalTime
)
Process{(Get-Date 1970-01-01 -AsUTC:$UniversalTime).AddSeconds($InputObject)}
7 changes: 4 additions & 3 deletions ConvertTo-EpochTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Converts a DateTime value into an integer Unix (POSIX) time, seconds since Jan 1, 1970.
.INPUTS
System.DateTime values to convert to integers.
System.DateTime value to convert to integer.
.OUTPUTS
System.Int32 values converted from date and time values.
System.Int32 value converted from date and time value.
.FUNCTIONALITY
Date and time
Expand All @@ -26,10 +26,11 @@ Get-Date |ConvertTo-EpochTime.ps1
1556884381
#>

#Requires -Version 3
[CmdletBinding()][OutputType([int])] Param(
# The DateTime value to convert to number of seconds since Jan 1, 1970.
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][DateTime] $DateTime,
# Indicates the DateTime provided is local, and should be converted to UTC.
[Alias('UTC')][switch] $UniversalTime
[Alias('UTC','Z')][switch] $UniversalTime
)
Process{[int][double]::Parse((Get-Date $(if($UniversalTime){$DateTime.ToUniversalTime()}else{$DateTime}) -UFormat %s))}
71 changes: 50 additions & 21 deletions Get-PocketArticles.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ Retrieves a list of saved articles from a Pocket account.
.OUTPUTS
System.Management.Automation.PSObject containing article details.
See https://getpocket.com/developer/docs/v3/retrieve for fields.
* ItemId: The article ID.
* Title: The simplified article title.
* Url: The resolved URL.
* IsFavorite: True if favorited.
* IsArchived: True if archived.
* WordCount: The approximate number of words in the article.
* AddedAt: DateTime the article was added.
* ReadAt: DateTime the article was read.
* UpdatedAt: DateTime the article was last updated.
* Tags: Keywords associated with the article.
* Language: Linguistic culture of the article.
* ReadDuration: The approximate time to listen to the article.
* FullTitle: The original article title.
* FullUrl: The original article URL.
* Excerpt: A summary of the article.
.NOTES
You'll need a "consumer key" (API key; see the link below to "create new app").
Expand All @@ -19,6 +33,9 @@ You can control whether the vault prompts for a password using Set-SecretStoreCo
.LINK
https://getpocket.com/developer/
.LINK
https://getpocket.com/developer/docs/v3/retrieve
.LINK
https://devblogs.microsoft.com/powershell/secretmanagement-and-secretstore-are-generally-available/
Expand All @@ -32,21 +49,19 @@ ConvertTo-EpochTime.ps1
Remove-NullValues.ps1
.EXAMPLE
Get-PocketArticles.ps1 2020-02-15 2021-03-01 -State Archive -Tag Programming -Sort Newest |Format-Table -Auto
Get-PocketArticles.ps1 2020-02-15 2021-03-01 -State Archive -Tag Programming -Sort Newest |Format-Table Title,WordCount,AddedAt -Auto
item_id resolved_id given_url given_title favorite status time_added time_updated time_read time_favorited
------- ----------- --------- ----------- -------- ------ ---------- ------------ --------- --------------
2713538930 2713538930 https://dev.to/thementor/i-run-powershell-on-android-and-so-can-you-458k I run PowerShell on Android and so can you !! - DEV Community 1 1 1610230461 1610432554 1610430179 1610432553
3002666222 3002666222 https://www.theregister.com/2020/06/01/linux_5_7/ 80-characters-per-line limits should be terminal, says Linux kernel chief L 0 1 1609706654 1609781229 1609781227 0
3195903579 3195903579 https://devblogs.microsoft.com/powershell/announcing-powershell-crescendo-preview-1/ Announcing PowerShell Crescendo Preview.1 | PowerShell 0 1 1607526051 1608436421 1608436415 0
3044493651 3044493651 https://www.compositional-it.com/news-blog/5-features-that-c-has-that-f-doesnt-have/ 5 Features C# Has That F# Doesn't Have! | Compositional IT 0 1 1594439301 1594500813 1594500812 0
2908050151 2908050151 https://thesharperdev.com/examples-using-httpclient-in-fsharp/ Examples Using HttpClient in F# – The Sharper Dev 0 1 1583616769 1583616987 1583616986 0
2907176185 2907176185 https://voiceofthedba.com/2020/03/06/the-developer-arguments-for-stored-procedures/ The Developer Arguments for Stored Procedures 0 1 1583519345 1583616940 1583616940 0
2903715421 2903715421 https://khalidabuhakmeh.com/upgraded-dotnet-console-experience Upgrade Your .NET Console App Experience | Khalid Abuhakmeh 0 1 1583440478 1583715611 1583715610 0
1526616723 1526616723 https://support.google.com/maps/answer/7047426? Find and share places using plus codes 0 1 1565309293 1610746653 1565642230 0
Title WordCount AddedAt
----- --------- -------
I run PowerShell on Android and so can you !! 540 2021-01-09 22:14:21
80-characters-per-line limits should be terminal, says Linux kernel chief Linus Torvalds 476 2021-01-03 20:44:14
Scott Hanselman's 2021 Ultimate Developer and Power Users Tool List for Windows 2201 2020-12-25 02:15:26
Announcing PowerShell Crescendo Preview.1 1319 2020-12-09 15:00:51
Windows Terminal Preview 1.5 out with a host of new features, version 1.4 generally available 448 2020-11-12 03:42:00
5 Features C# Has That F# Doesn’t Have! 1489 2020-07-11 03:48:21
#>

#Requires -Version 3
#Requires -Version 7
#Requires -Modules Microsoft.PowerShell.SecretManagement,Microsoft.PowerShell.SecretStore
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText','',
Justification='This value has to be converted to text to be sent in a text body.')]
Expand All @@ -73,9 +88,7 @@ By default, the default vault is used.
#>
[string] $Vault,
# Return only favorite articles.
[switch] $Favorite,
# Return full article details.
[switch] $Detailed
[switch] $Favorite
)
Set-ParameterDefault.ps1 Invoke-RestMethod Method Post
Set-ParameterDefault.ps1 Invoke-RestMethod ContentType application/json
Expand Down Expand Up @@ -122,15 +135,31 @@ $articles = @{
tag = $Tag
contentType = if($ContentType) {$ContentType.ToLower()};
sort = if($Sort) {$Sort.ToLower()};
detailType = if($Detailed) {'complete'} else {'simple'};
detailType = 'complete'
search = $Search
domain = $Domain
since = ConvertTo-EpochTime.ps1 $After
} |
Remove-NullValues.ps1 |
ConvertTo-Json -Compress |
Invoke-RestMethod https://getpocket.com/v3/get
if($articles -and $articles.list)
{
$articles.list.PSObject.Properties.Value |Where-Object time_read -lt (ConvertTo-EpochTime.ps1 $Before)
}
${articles}?.{list}?.{PSObject}?.{Properties}?.Value |
ForEach-Object {[pscustomobject]@{
ItemId = $_.item_id
Title = $_.resolved_title
Url = [uri]$_.resolved_url
IsFavorite = [bool]$_.favorite
IsArchived = [bool]$_.status
WordCount = [long]$_.word_count
AddedAt = ConvertFrom-EpochTime.ps1 $_.time_added
ReadAt = ConvertFrom-EpochTime.ps1 $_.time_read
UpdatedAt = ConvertFrom-EpochTime.ps1 $_.time_updated
Tags = @($_.{tags}?.{PSObject}?.{Properties}?.Name)
#TODO: Image = $_.{image}?.src
Language = Get-Culture $_.lang
ReadDuration = [timespan]::FromSeconds($_.listen_duration_estimate)
FullTitle = $_.given_title
FullUrl = [uri]$_.given_url
Excerpt = $_.excerpt
}} |
Where-Object ReadAt -lt $Before
31 changes: 16 additions & 15 deletions Get-Todos.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ Get-Todos.ps1 |Out-GridView -Title "$((Get-Item $(git rev-parse --show-toplevel)
Shows TODOs in this repo.
#>

#Requires -Version 3
#Requires -Version 7
[CmdletBinding()] Param()

Push-Location $(git rev-parse --show-toplevel)
Find-Lines.ps1 TODO * src -Simple -CaseSensitive |
ForEach-Object {
$blame = git blame -p -L "$($_.LineNumber),$($_.LineNumber)" -- $_.Path
$author = $blame |Where-Object {$_ -match '^author (?<Author>.*)$'} |ForEach-Object {$Matches.Author}
$Time = $blame |Where-Object {$_ -match '^author-time (?<Time>.*)$'} |ForEach-Object {(Get-Date 1970-01-01).AddSeconds([int]$Matches.Time)}
[pscustomobject]@{
Author = $author
Time = $time
Todo = ($_.Line -split 'TODO:?\s*',2)[1].Trim()
Path = Resolve-Path $_.Path -Relative
LineNumber = $_.LineNumber
}
} |
Sort-Object Time -Descending
Find-Lines.ps1 -Pattern '\bTODO\b' -Filters * -Path ((Test-Path src -Type Container) ? 'src' : '.') -CaseSensitive |
ForEach-Object {
[string[]] $blame = git blame -p -L "$($_.LineNumber),$($_.LineNumber)" -- $_.Path
$author = $blame |Select-String '^author (?<Author>.*)$' |Select-CapturesFromMatches.ps1 -ValuesOnly
$Time = $blame |Select-String '^author-time (?<Time>.*)$' |Select-CapturesFromMatches.ps1 -ValuesOnly |
ConvertFrom-EpochTime.ps1
[pscustomobject]@{
Author = $author
Time = $time
Todo = ($_.Line -split 'TODO:?\s*',2)[1].Trim()
Path = Resolve-Path $_.Path -Relative
LineNumber = $_.LineNumber
}
} |
Sort-Object Time -Descending
Pop-Location
2 changes: 1 addition & 1 deletion Select-CapturesFromMatches.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Tricia McMillan [email protected]
[CmdletBinding()][OutputType([psobject])] Param(
# The MatchInfo output from Select-String to select named capture group values from.
[Parameter(Position=0,ValueFromRemainingArguments=$true,ValueFromPipeline=$true)]
[Alias('InputObject')][Microsoft.PowerShell.Commands.MatchInfo]$MatchInfo,
[Alias('InputObject')][Microsoft.PowerShell.Commands.MatchInfo] $MatchInfo,
# Return the capture group values without building objects.
[switch] $ValuesOnly
)
Expand Down

0 comments on commit 1162c75

Please sign in to comment.