Advertisement
Guest User

gw2raidar-auto-uploader

a guest
Oct 27th, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-Type -Path RestSharp.dll
  2.  
  3. $gw2raidar_url = "https://www.gw2raidar.com"
  4. $last_upload_file = "last_upload_time.json"
  5. $arcdps_logs = "<PATH TO arcdps.cbtlogs GOES HERE>"
  6. $username = '<YOUR USERNAME HERE>'
  7. $password = '<YOUR PASSWORD HERE>'
  8.  
  9. # Lookup all files since the last time we uploaded anything
  10. if (Test-Path $last_upload_file) {
  11.     $last_upload_time = Get-Content -Raw -Path $last_upload_file | ConvertFrom-Json | Select-Object -ExpandProperty "DateTime" | Get-Date
  12.     $files = @(Get-ChildItem -Recurse -File -Include "*.evtc.zip" -Name -LiteralPath $arcdps_logs | Where-Object { $_.LastWriteTime -gt $last_upload_time})
  13. } else {
  14.     $files = @(Get-ChildItem -Recurse -File -Include "*.evtc.zip" -Name -LiteralPath $arcdps_logs)
  15. }
  16.  
  17. ForEach($f in $files) {
  18.     Write-Output "Uploading ${f}"
  19.     $f = Join-Path $arcdps_logs $f
  20.     try {
  21.         $client = New-Object RestSharp.RestClient($gw2raidar_url)
  22.         $req = New-Object RestSharp.RestRequest("/api/upload.json")
  23.         $req.Method = [RestSharp.Method]::POST
  24.  
  25.         $req.AddFile("file", $f) | Out-Null
  26.         $req.AddParameter("username", $username) | Out-Null
  27.         $req.AddParameter("password", $password) | Out-Null
  28.         $resp = $client.Execute($req)
  29.  
  30.         if ($resp.ResponseStatus -ne [RestSharp.ResponseStatus]::Completed) {
  31.             throw "Request was not completed"
  32.         }
  33.  
  34.         if ($resp.StatusCode -ne "OK") {
  35.             throw "Request failed with status $resp.StatusCode"
  36.         }
  37.         Write-Output $resp.Content
  38.         Write-Output "Upload successful..."
  39.     } catch {
  40.         Write-Output $_.Exception.Message
  41.         Write-Output "Upload failed..."
  42.         Read-Host -Prompt "Press Enter to exit"
  43.         exit
  44.     }
  45. }
  46.  
  47. # Save the current time as
  48. Get-Date | Select-Object -Property DateTime | ConvertTo-Json | Out-File -Force $last_upload_file
  49.  
  50. Read-Host -Prompt "Press Enter to exit"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement