Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Скриптовые языки администрирования Windows (http://forum.oszone.net/forumdisplay.php?f=102)
-   -   Для любителей цитат. Get-Quote (JFF) (http://forum.oszone.net/showthread.php?t=247137)

Foreigner 17-11-2012 19:37 2027407

Для любителей цитат. Get-Quote (JFF)
 
Может кому пригодится:
Код:

#
# get-quote.ps1
#

$random = new-object random
$xml = new-object xml

switch ( ($random.next(1,10) % 2) ) {

    0 { $lang = 'ru' }
    1 { $lang = 'en' }

}

$key = $random.next(1,999999)
$url = "http://api.forismatic.com/api/1.0/?&method=getQuote&format=xml&key=$key&lang=$lang"

$xml.load($url)

$author = $xml.forismatic.quote.quoteAuthor
$quote  = $xml.forismatic.quote.quotetext

if ($author) { "`n | $($author):" } else { "`n" }; " | "

$quote = @($quote.split([char]32))
$quote[0] = "  $($quote[0])"

foreach ($word in $quote ) {
 
    $substring += "$($word) "
    if ($substring.length -ge 50) {

        " | $($substring)"
        $substring = $null

    }

}

if ($substring) { " | $($substring)" }; " | `n"



Время: 19:19.

Время: 19:19.
© OSzone.net 2001-