Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1.  
  2. <#
  3. Доработать:
  4. 1. Найти вариант нормальное перекодировки без использования файлов
  5. 2. Удалять из статьи прошлые версии
  6. 3. Изменять недопустимые символы более правильным способом, чем replac
  7.  
  8. #>
  9.  
  10. function transfername {
  11. param (
  12. [string][parameter(mandatory=$true)] $login
  13. )
  14.  
  15. switch ($login)
  16. {
  17. 'sovaenga' {return 'Шамарин Олег'}
  18. 'rusanovskiy' {return 'Русановский Михаил'}
  19. 'tedman.' {return 'Бобров Фёдор'}
  20. 'kasoy77712' {return 'Косилов Никита'}
  21. 'azaitseva' {return 'Зайцева Анна'}
  22. 'alex_rumyantsev' {return 'Румянцев Александр'}
  23. 'oxancheg1' {return 'Литвиненко Оксана'}
  24. 'r.aleinikov' {return 'Алейников Роман'}
  25. 'alexn_morozov' {return 'Морозов Александр'}
  26. 'golikovab' {return 'Голиков Александр'}
  27. 'lees_86' {return 'Ксёнз Вячеслав'}
  28. 'regniws' {return 'regniws'}
  29. 'andrew.smirnoff' {return 'Смирнов Андрей'}
  30. 'oleglm' {return 'Меломуд Олег'}
  31. default {$login}
  32. }
  33.  
  34. }
  35.  
  36. function getskypemessages {
  37.  
  38. $skype = New-Object -COM "Skype4COM.Skype"
  39. $skype.Attach()
  40. $measure = Measure-Command {
  41. $messages = $skype.Messages() | ? {$_.ChatName -eq '19:0579cc34217042758f9311441e7acfd7@thread.skype'} `
  42. | Select-Object FromHandle,Body,Timestamp
  43. }
  44. <#
  45. 4 минуты 43 секунды с @{Label="UserName"; Expression={transfername $_.FromHandle}
  46. 56 секунд без
  47. #>
  48. $skype = $null
  49.  
  50. return $messages
  51.  
  52. }
  53.  
  54. function SendMessagesToConfluence {
  55. param ($messages)
  56.  
  57. $page_id = '7143682'
  58.  
  59. $Headers = @{};
  60.  
  61. <#
  62. Как получить значение параметра: $Headers["Authorization"] = "Basic Ygdfg78689SDFGdfgjklv78gGFglhwe786";
  63. $login = 'pupkin'
  64. $pass = 'P@ssw0rd!'
  65. $bytes = [System.Text.Encoding]:: UTF8. GetBytes( " $($login ):$( $pass) " );
  66. $b64 = [System.Convert]:: ToBase64String($bytes );
  67. $value = "Basic $b64"
  68. #>
  69.  
  70. $Headers["Authorization"] = "Basic Ygdfg78689SDFGdfgjkgsdg34FGDGJe786";
  71. $Headers["Accept-Charset"] = "utf-8";
  72.  
  73. $tempfile = [io.path]::GetTempFileName()
  74.  
  75. # Т.к. я не смог побороть кодировку, получаемую по умолчанию, будем работать через файл
  76. Invoke-RestMethod -Uri 'http://confluence.fresh/rest/api/content/7143682?expand=space,body.view,version,container' `
  77. -Headers $Headers `
  78. -ContentType 'application/json' `
  79. -Method Get `
  80. -OutFile $tempfile
  81.  
  82. $content = Get-Content $tempfile -Encoding UTF8 | ConvertFrom-Json
  83.  
  84. $lastversion = $content.version.number
  85. $space_key = $content.space.key
  86. $page_title = $content.title
  87. # Найти в соответствующем месте дату последнего сообщения
  88.  
  89. $text = ''
  90. $n=0
  91. $lastuser = ''
  92. $messages | foreach {
  93. if ($_.Body)
  94. {#247
  95. $n++; if($n -lt 1000) {
  96.  
  97. $bodytext = $_.Body
  98. if ($bodytext -match '<<<')
  99. {
  100. $bodytext = '&em&'+($bodytext -replace ('<<<','&/emquote&'))
  101. }
  102.  
  103. #,@{Label="UserName"; Expression={transfername $_.FromHandle}}
  104. $bodytext = $bodytext -replace ('<','!!!Недопустимый символ 1!!!')
  105. $bodytext = $bodytext -replace ('>','!!!Недопустимый символ 2!!!')
  106. $bodytext = $bodytext -replace ('&em&','<em>')
  107. $bodytext = $bodytext -replace ('&/emquote&','</em> <br />')
  108. $bodytext = $bodytext -replace ('&','!!!Недопустимый символ 3!!!')
  109. $bodytext = $bodytext -replace ('\n','<br />')
  110. if($n -eq 1099) {
  111. $bodytext
  112. }
  113.  
  114.  
  115. if ($lastuser -eq $_.FromHandle) {
  116. $message = $bodytext + '<br />' + $message
  117. } else {
  118. if ($lastuser) {$text = $text + $message + '</p>'}
  119. $text = $text + '<p> <strong>'+$_.Timestamp.ToString('dd.MM.yyyy hh:mm:ss')+'</strong>; <strong>'+(transfername $_.FromHandle)+'</strong><br />'
  120. $message = $bodytext
  121. $lastuser = $_.FromHandle
  122. }
  123.  
  124.  
  125. <# backup
  126. if ($lastuser -eq $_.FromHandle) {
  127. $text = $bodytext + '<br />' + $text
  128. } else {
  129. $text = $text + '<p> <strong>'+$_.Timestamp.ToString('dd.MM.yyyy hh:mm:ss')+'</strong>; <strong>'+(transfername $_.FromHandle)+'</strong><br />'+$bodytext+'</p>'
  130. }
  131. $lastuser = $_.FromHandle
  132. #>
  133. }
  134. }
  135. }
  136.  
  137. if ($message) {$text = $text + $message + '</p>'}
  138.  
  139. # $text > c:\123.html # для отладки
  140. $data = [ordered]@{}
  141. $data['id']=$page_id
  142. $data['type']='page'
  143. $data['title']=$page_title
  144. $data['space']=@{key=$space_key}
  145.  
  146. $body = @{}
  147. $body['storage'] = [ordered]@{value=$text; representation='storage'}
  148.  
  149. $data['body']=$body
  150. $data['version']=@{number=$($lastversion+1)}
  151. $data | ConvertTo-Json | Out-File $tempfile
  152.  
  153. $response = Invoke-RestMethod -Uri 'http://confluence.fresh/rest/api/content/7143682' `
  154. -Headers $Headers `
  155. -ContentType 'application/json' `
  156. -Method Put `
  157. -InFile $tempfile
  158.  
  159.  
  160.  
  161.  
  162. $tempfile | Remove-Item
  163.  
  164. }
  165.  
  166. function UpdateSkypeHistoryOnConfluence {
  167.  
  168. $messages = getskypemessages
  169. SendMessagesToConfluence($messages)
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement