Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Доработать:
- 1. Найти вариант нормальное перекодировки без использования файлов
- 2. Удалять из статьи прошлые версии
- 3. Изменять недопустимые символы более правильным способом, чем replac
- #>
- function transfername {
- param (
- [string][parameter(mandatory=$true)] $login
- )
- switch ($login)
- {
- 'sovaenga' {return 'Шамарин Олег'}
- 'rusanovskiy' {return 'Русановский Михаил'}
- 'tedman.' {return 'Бобров Фёдор'}
- 'kasoy77712' {return 'Косилов Никита'}
- 'azaitseva' {return 'Зайцева Анна'}
- 'alex_rumyantsev' {return 'Румянцев Александр'}
- 'oxancheg1' {return 'Литвиненко Оксана'}
- 'r.aleinikov' {return 'Алейников Роман'}
- 'alexn_morozov' {return 'Морозов Александр'}
- 'golikovab' {return 'Голиков Александр'}
- 'lees_86' {return 'Ксёнз Вячеслав'}
- 'regniws' {return 'regniws'}
- 'andrew.smirnoff' {return 'Смирнов Андрей'}
- 'oleglm' {return 'Меломуд Олег'}
- default {$login}
- }
- }
- function getskypemessages {
- $skype = New-Object -COM "Skype4COM.Skype"
- $skype.Attach()
- $measure = Measure-Command {
- $messages = $skype.Messages() | ? {$_.ChatName -eq '19:0579cc34217042758f9311441e7acfd7@thread.skype'} `
- | Select-Object FromHandle,Body,Timestamp
- }
- <#
- 4 минуты 43 секунды с @{Label="UserName"; Expression={transfername $_.FromHandle}
- 56 секунд без
- #>
- $skype = $null
- return $messages
- }
- function SendMessagesToConfluence {
- param ($messages)
- $page_id = '7143682'
- $Headers = @{};
- <#
- Как получить значение параметра: $Headers["Authorization"] = "Basic Ygdfg78689SDFGdfgjklv78gGFglhwe786";
- $login = 'pupkin'
- $pass = 'P@ssw0rd!'
- $bytes = [System.Text.Encoding]:: UTF8. GetBytes( " $($login ):$( $pass) " );
- $b64 = [System.Convert]:: ToBase64String($bytes );
- $value = "Basic $b64"
- #>
- $Headers["Authorization"] = "Basic Ygdfg78689SDFGdfgjkgsdg34FGDGJe786";
- $Headers["Accept-Charset"] = "utf-8";
- $tempfile = [io.path]::GetTempFileName()
- # Т.к. я не смог побороть кодировку, получаемую по умолчанию, будем работать через файл
- Invoke-RestMethod -Uri 'http://confluence.fresh/rest/api/content/7143682?expand=space,body.view,version,container' `
- -Headers $Headers `
- -ContentType 'application/json' `
- -Method Get `
- -OutFile $tempfile
- $content = Get-Content $tempfile -Encoding UTF8 | ConvertFrom-Json
- $lastversion = $content.version.number
- $space_key = $content.space.key
- $page_title = $content.title
- # Найти в соответствующем месте дату последнего сообщения
- $text = ''
- $n=0
- $lastuser = ''
- $messages | foreach {
- if ($_.Body)
- {#247
- $n++; if($n -lt 1000) {
- $bodytext = $_.Body
- if ($bodytext -match '<<<')
- {
- $bodytext = '&em&'+($bodytext -replace ('<<<','&/emquote&'))
- }
- #,@{Label="UserName"; Expression={transfername $_.FromHandle}}
- $bodytext = $bodytext -replace ('<','!!!Недопустимый символ 1!!!')
- $bodytext = $bodytext -replace ('>','!!!Недопустимый символ 2!!!')
- $bodytext = $bodytext -replace ('&em&','<em>')
- $bodytext = $bodytext -replace ('&/emquote&','</em> <br />')
- $bodytext = $bodytext -replace ('&','!!!Недопустимый символ 3!!!')
- $bodytext = $bodytext -replace ('\n','<br />')
- if($n -eq 1099) {
- $bodytext
- }
- if ($lastuser -eq $_.FromHandle) {
- $message = $bodytext + '<br />' + $message
- } else {
- if ($lastuser) {$text = $text + $message + '</p>'}
- $text = $text + '<p> <strong>'+$_.Timestamp.ToString('dd.MM.yyyy hh:mm:ss')+'</strong>; <strong>'+(transfername $_.FromHandle)+'</strong><br />'
- $message = $bodytext
- $lastuser = $_.FromHandle
- }
- <# backup
- if ($lastuser -eq $_.FromHandle) {
- $text = $bodytext + '<br />' + $text
- } else {
- $text = $text + '<p> <strong>'+$_.Timestamp.ToString('dd.MM.yyyy hh:mm:ss')+'</strong>; <strong>'+(transfername $_.FromHandle)+'</strong><br />'+$bodytext+'</p>'
- }
- $lastuser = $_.FromHandle
- #>
- }
- }
- }
- if ($message) {$text = $text + $message + '</p>'}
- # $text > c:\123.html # для отладки
- $data = [ordered]@{}
- $data['id']=$page_id
- $data['type']='page'
- $data['title']=$page_title
- $data['space']=@{key=$space_key}
- $body = @{}
- $body['storage'] = [ordered]@{value=$text; representation='storage'}
- $data['body']=$body
- $data['version']=@{number=$($lastversion+1)}
- $data | ConvertTo-Json | Out-File $tempfile
- $response = Invoke-RestMethod -Uri 'http://confluence.fresh/rest/api/content/7143682' `
- -Headers $Headers `
- -ContentType 'application/json' `
- -Method Put `
- -InFile $tempfile
- $tempfile | Remove-Item
- }
- function UpdateSkypeHistoryOnConfluence {
- $messages = getskypemessages
- SendMessagesToConfluence($messages)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement