GenXdev.Queries.psm1
function Open-AllPossibleTextQueries { [CmdletBinding()] [Alias("qqq")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries ) process { foreach ($Query in $Queries) { try { Clear-Host [Uri] $uri = $null; $q = $Query.Trim("`"").Trim("'"); $isUri = ( [Uri]::TryCreate($q, "absolute", [ref] $uri) -or ( $Query.ToLowerInvariant().StartsWith("www.") -and [Uri]::TryCreate("http://$q", "absolute", [ref] $uri) ) ) -and $uri.IsWellFormedOriginalString() -and $uri.Scheme -like "http*"; if ($isUri) { "`r`nSearched for URL : $Query" | Write-Host -ForegroundColor "DarkGreen" Get-Command -Module "*.Queries" -ErrorAction SilentlyContinue | ForEach-Object Name | ForEach-Object -ThrottleLimit 64 -Parallel { if ($using:isUri -and $PSItem.EndsWith("SiteSummary") -and $PSItem.StartsWith("Get-")) { try { "`r`n" + $PSItem.SubString("Get-".Length, $PSItem.Length - "Get-SiteSummary".Length) + ":" | Write-Host -ForegroundColor "Blue" $exp = Invoke-Expression "$PSItem $($using:uri.DnsSafeHost)" Write-Output $exp if ($PSItem.EndsWith("HostSiteSummary") -eq $false) { $safeUrl = ($using:Query).Split("#")[0]; if ($using:Uri.Query.Length -gt 0) { $safeUrl = $safeUrl.Replace($using:Uri.Query, ""); } $line = "`r`n" + $PSItem.SubString("Get-".Length, $PSItem.Length - "Get-HostSiteSummary".Length).Replace("Gpt3", "Generative Pre-trained Transformer 3 (GPT-3) - ") + ":`r`n"; $line = $line + (Invoke-Expression "$PSItemsafeUrl") + "`r`n" Write-Output $line; } } Catch { } } } return; } } catch { throw $PSItem } "`r`nSearched for: $Query" | Write-Host -ForegroundColor "DarkGreen" Get-Command -Module "*.Queries" -ErrorAction SilentlyContinue | ForEach-Object Name | ForEach-Object -ThrottleLimit 64 -Parallel { if ($PSItem.EndsWith("Summary") -and $PSItem.StartsWith("Get-")) { try { $line = "`r`n" + $PSItem.SubString("Get-".Length, $PSItem.Length - "Get-Summary".Length).Replace("Gpt3", "Generative Pre-trained Transformer 3 (GPT-3) - ") + ":`r`n"; $line = $line + (Invoke-Expression "$PSItem $using:Query") + "`r`n" Write-Output $line; } catch { } } } | ForEach-Object { $lines = $PSItem.Split("`r`n", [System.StringSplitOptions]::RemoveEmptyEntries); "`r`n$($lines[0])" | Write-Host -ForegroundColor Yellow; $lines | Select-Object -Skip 1 | Write-Output } "`r`n-------------" | Write-Host -ForegroundColor "DarkGreen" } } } ###################################################################################################################################################### function Open-AllPossibleQueries { [CmdletBinding()] [Alias("qq")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries ) process { foreach ($Query in $Queries) { try { [Uri] $uri = $null; $q = $Query.Trim("`"").Trim("'"); $isUri = ( [Uri]::TryCreate($q, "absolute", [ref] $uri) -or ( $Query.ToLowerInvariant().StartsWith("www.") -and [Uri]::TryCreate("http://$q", "absolute", [ref] $uri) ) ) -and $uri.IsWellFormedOriginalString() -and $uri.Scheme -like "http*"; if ($isUri) { Get-Command -Module "*.Queries" -ErrorAction SilentlyContinue | ForEach-Object Name | ForEach-Object -Process { if ($isUri -and $PSItem.EndsWith("SiteInfo") -and $PSItem.StartsWith("Open-")) { Invoke-Expression "$PSItem $($uri.DnsSafeHost)" if ($PSItem.EndsWith("HostSiteInfo") -eq $false) { $safeUrl = $Query.Split("#")[0]; if ($Uri.Query.Length -gt 0) { $safeUrl = $safeUrl.Replace($Uri.Query, ""); } Invoke-Expression "$PSItem $safeUrl" } } } return; } } catch { throw $PSItem } Get-Command -Module "*.Queries" -ErrorAction SilentlyContinue | ForEach-Object Name | ForEach-Object -Process { if ($PSItem.EndsWith("Query") -and $PSItem.StartsWith("Open-")) { Invoke-Expression "$PSItem $Query" } } } } } ###################################################################################################################################################### ###################################################################################################################################################### function Open-GoogleQuery { [CmdletBinding()] [Alias("q")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://www.google.com/search?q=$([Uri]::EscapeUriString($Query))"; Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-WikipediaQuery { [CmdletBinding()] [Alias("wiki")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://en.wikipedia.org/wiki/Special:Search?search=$([Uri]::EscapeUriString($Query))"; Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-WikipediaNLQuery { [CmdletBinding()] [Alias("wikinl")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://nl.wikipedia.org/wiki/Special:Search?search=$([Uri]::EscapeUriString($Query))" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-YoutubeQuery { [CmdletBinding()] [Alias("youtube")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://www.youtube.com/results?search_query=$([Uri]::EscapeUriString($Query))" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-IMDBQuery { [CmdletBinding()] [Alias("imdb")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://www.imdb.com/find?q=$([Uri]::EscapeUriString($Query))&ref_=nv_sr_sm=" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-StackOverflowQuery { [CmdletBinding()] [Alias("qso")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://stackoverflow.com/search?q=$([Uri]::EscapeUriString($Query))" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-WolframAlphaQuery { [CmdletBinding()] [Alias("qalpha")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://www.wolframalpha.com/input/?i=$([Uri]::EscapeUriString($Query))"; Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-GithubQuery { [CmdletBinding()] [Alias("qgit")] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, [parameter( Mandatory = $false )] [string] $Language = "", #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { if ([string]::IsNullOrWhiteSpace($Language)) { $Language = "" } else { $Language = "l=$([Uri]::EscapeUriString($Language))&" } $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Remove("Language") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://github.com/search?q=$([Uri]::EscapeUriString($Query))$Language&type=repositories" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### ###################################################################################################################################################### function Open-GoogleSiteInfo { [CmdletBinding()] [Alias()] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { foreach ($Query in $Queries) { $q = $Query; $PSBoundParameters["Query"] = "site:$q"; Open-GoogleQuery @PSBoundParameters $PSBoundParameters["Query"] = "link:$q"; Open-GoogleQuery @PSBoundParameters $PSBoundParameters["Query"] = "related:$q"; Open-GoogleQuery @PSBoundParameters } } } ###################################################################################################################################################### function Open-BuiltWithSiteInfo { [CmdletBinding()] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://builtwith.com/?$([Uri]::EscapeUriString($Query))" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-WhoisHostSiteInfo { [CmdletBinding()] [Alias()] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://whois.domaintools.com/$([Uri]::EscapeUriString($Query))" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-WaybackMachineSiteInfo { [CmdletBinding()] [Alias()] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://web.archive.org/web/*/$([Uri]::EscapeUriString($Query))" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### function Open-SimularWebSiteInfo { [CmdletBinding()] [Alias()] param( [Alias("q", "Value", "Name", "Text")] [parameter( Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries, #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Remove("Queries") | Out-Null; $PSBoundParameters.Add("Url", "Url") | Out-Null; foreach ($Query in $Queries) { $PSBoundParameters["Url"] = "https://www.similarweb.com/website/$([Uri]::EscapeUriString($Query))" Open-Webbrowser @PSBoundParameters } } } ###################################################################################################################################################### ###################################################################################################################################################### function Get-WikipediaSummary { [CmdletBinding()] [Alias("wikitxt")] Param( [Alias("q", "Value", "Name", "Text")] [Parameter( Mandatory = $True, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries ) function fixWiki ([string]$text) { $input | ForEach-Object -Process { $i = $_.IndexOf("(") if ($i -lt 150) { if ($result.Length - 1 -eq $i) { Write-Output $result.SubString(0, $i).Replace(" ", " "); } else { $end = $_.IndexOf(")", $i); $result = $_.Substring(0, $i) if ($end -lt $_.Length) { $result = $result + $_.Substring($end + 1) } Write-Output $result.Replace(" ", " "); } } } } $urlPart = [Uri]::EscapeUriString($Query.Replace("-", " ")) $url = ("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=1&explaintext=1&titles=" + $urlPart) $r = (Invoke-WebRequest -Uri $url -MaximumRedirection 20).Content | ConvertFrom-Json $memberName = ($r.query.pages | Get-Member | Where-Object -Property "MemberType" -EQ "NoteProperty" | Select-Object -ExpandProperty "Name" | Select-Object -First 1) $value = ($r.query.pages | Select-Object -ExpandProperty $memberName) $result = $value.extract if ((!$result) -or ($result -eq "")) { return "Nothing found on `"$Query`".." } try { $result = ($result | fixWiki) } catch { $result = $value.extract } return $result } ###################################################################################################################################################### function Get-Gpt3QuestionSummary { [CmdletBinding()] [Alias("q3")] Param( [Alias("q", "Value", "Name", "Text")] [Parameter( Mandatory = $True, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries ) if ([string]::IsNullOrWhiteSpace($Global:GPT3ApiKey)) { throw "No api key found, please set `$Global:GPT3ApiKey variable in your profile script" } $result = [GenXdev.Helpers.GPT3]::AskQuestion($Global:GPT3ApiKey, $Query) if ((!$result) -or ($result -eq "") -or ($result.Result -like "Unknown *")) { return "Nothing found on `"$Query`".." } return "$($result.Result)".Trim(); } ###################################################################################################################################################### function Get-Gpt3EnglishSummary { [CmdletBinding()] [Alias("q3")] Param( [Alias("q", "Value", "Name", "Text")] [Parameter( Mandatory = $True, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries ) if ([string]::IsNullOrWhiteSpace($Global:GPT3ApiKey)) { throw "No api key found, please set `$Global:GPT3ApiKey variable in your profile script" } $result = [GenXdev.Helpers.GPT3]::CorrectGrammar($Global:GPT3ApiKey, $Query, "English") if ((!$result) -or ($result -eq "") -or ($result.Result -like "Unknown *")) { return "Nothing found on `"$Query`".." } return "$($result.Result)".Split("`n")[0].Trim(); } ###################################################################################################################################################### function Get-Gpt3DutchSummary { [CmdletBinding()] [Alias("q3")] Param( [Alias("q", "Value", "Name", "Text")] [Parameter( Mandatory = $True, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string[]] $Queries ) if ([string]::IsNullOrWhiteSpace($Global:GPT3ApiKey)) { throw "No api key found, please set `$Global:GPT3ApiKey variable in your profile script" } $result = [GenXdev.Helpers.GPT3]::CorrectGrammar($Global:GPT3ApiKey, $Query, "Dutch") if ((!$result) -or ($result -eq "") -or ($result.Result -like "Unknown *")) { return "Nothing found on `"$Query`".." } return "$($result.Result)".Split("`n")[0].Trim(); } ###################################################################################################################################################### ###################################################################################################################################################### function Get-NextAffirmations { [CmdletBinding()] [Alias("WhatAboutIt")] Param( [Parameter( Mandatory = $False, Position = 0 )] [Switch] $Speak ) $affirmation = (Invoke-RestMethod https://www.affirmations.dev/).affirmation; if ($Speak -eq $true) { say $affirmation } Write-Output $affirmation } ###################################################################################################################################################### function Get-NextJoke { [CmdletBinding()] [Alias("TellAJoke")] Param( [Parameter( Mandatory = $False, Position = 0 )] [Switch] $Speak ) $joke = [System.Web.HttpUtility]::HtmlDecode((Invoke-RestMethod https://icanhazdadjoke.com/ -Headers @{"Accept" = "text/plain" })); if ($Speak -eq $true) { say $joke } Write-Output $joke } ###################################################################################################################################################### function Open-Repeaters { [CmdletBinding()] [Alias()] Param( [Alias("q", "Value", "Name", "Text")] [Parameter( Mandatory = $false, Position = 0, ValueFromRemainingArguments = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [ValidateSet("PI2NOS", "PI3UTR", "PI3GOE", "MEETNET", "PI6NOS", "PI1DFT")] [string[]] $Repeaters = @("PI6NOS"), #################################################################################################### [Alias("m", "mon")] [parameter( Mandatory = $false, HelpMessage = "The monitor to use, 0 = default, -1 is discard" )] [int] $Monitor = -1 ) DynamicParam { Copy-OpenWebbrowserParameters -ParametersToSkip "Url", "Monitor" } process { $PSBoundParameters.Add("Url", "https://pc7x.net/repeaters/") | Out-Null; $PSBoundParameters.Remove("Repeater") | Out-Null; foreach ($Repeater in $Repeaters) { $PSBoundParameters["Url"] = "https://pc7x.net/repeaters/#/map/google/$($Repeater.ToLowerInvariant())"; Open-Webbrowser @PSBoundParameters } } } |