add modules google api
This commit is contained in:
parent
844816c057
commit
a0a06880c9
2 changed files with 42 additions and 0 deletions
16
Scripts/Find-Google.psm1
Normal file
16
Scripts/Find-Google.psm1
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
function Find-Google {
|
||||||
|
param (
|
||||||
|
$Query,
|
||||||
|
$Lang = "ru",
|
||||||
|
$Num = 10,
|
||||||
|
$Start = 0,
|
||||||
|
$Key = "<TOKEN_API>",
|
||||||
|
$cx = "35c78340f49eb474a"
|
||||||
|
)
|
||||||
|
$query
|
||||||
|
$response = Invoke-RestMethod "https://www.googleapis.com/customsearch/v1?q=$Query&key=$Key&cx=$cx&lr=lang_$Lang&num=$Num&$start=$Start"
|
||||||
|
$response.items | Select-Object title,snippet,displayLink,link | Format-List
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find-Google "как создать бота discord"
|
||||||
|
# Find-Google "как создать бота discord" -Lang ru -Num 10 -Start 9
|
||||||
26
Scripts/Get-GoogleTranslate.ps1
Normal file
26
Scripts/Get-GoogleTranslate.ps1
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Module: https://github.com/Lifailon/Console-Translate
|
||||||
|
function Get-GoogleTranslate {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory,ValueFromPipeline)][string[]]$Text,
|
||||||
|
[string]$LanguageTarget = "RU",
|
||||||
|
[string]$LanguageSource,
|
||||||
|
[string]$Key = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" # Public API Key for Google Translate
|
||||||
|
)
|
||||||
|
$url = "https://translation.googleapis.com/language/translate/v2?key=${key}"
|
||||||
|
$Header = @{
|
||||||
|
"Content-Type" = "application/json"
|
||||||
|
}
|
||||||
|
$Body = @{
|
||||||
|
"q" = "$Text"
|
||||||
|
"target" = "$LanguageTarget"
|
||||||
|
"source" = "$LanguageSource"
|
||||||
|
} | ConvertTo-Json
|
||||||
|
$WebClient = New-Object System.Net.WebClient
|
||||||
|
foreach ($key in $Header.Keys) {
|
||||||
|
$WebClient.Headers.Add($key, $Header[$key])
|
||||||
|
}
|
||||||
|
$Response = $WebClient.UploadString($url, "POST", $Body) | ConvertFrom-Json
|
||||||
|
$Response.data.translations.translatedText
|
||||||
|
}
|
||||||
|
|
||||||
|
Get-GoogleTranslate -Text "Привет" -LanguageTarget en
|
||||||
Loading…
Add table
Add a link
Reference in a new issue