Войти

Показать полную графическую версию : Для любителей цитат. Get-Quote (JFF)


Foreigner
17-11-2012, 19:37
Может кому пригодится:

#
# 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"




© OSzone.net 2001-2012