Last active
January 25, 2016 16:43
-
-
Save jarig/2353408b813edcdb8ccd to your computer and use it in GitHub Desktop.
Отправка отчетов из EliteReporter на форму EG UNION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Настройки для EliteReporter | |
Application->Settings | |
Executable to run on Export | |
powershell.exe | |
Arguments | |
"& ""E:\temp\elite_games_send_report.ps1""" -jsonFile $exportedFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$jsonFile | |
) | |
# read json | |
$reportData = (Get-Content $jsonFile) | ConvertFrom-Json | |
$cmdrName = $reportData.CommanderName | |
$numberOfMissions = $reportData.Missions.Count | |
#group by system & station | |
$missionInfo = @{} | |
$totalReward = 0 | |
$earliestDate = $null | |
$latestDate = $null | |
foreach($mission in $reportData.Missions) | |
{ | |
$totalReward += $mission.Reward | |
if ($mission.MissionFinishedDateTime -eq $null) | |
{ | |
continue; | |
} | |
$finishTime = [datetime]$mission.MissionFinishedDateTime | |
if ($earliestDate -eq $null -or $finishTime -lt $earliestDate) | |
{ | |
$earliestDate = $finishTime | |
} | |
if ($latestDate -eq $null -or $finishTime -gt $latestDate) | |
{ | |
$latestDate = $finishTime | |
} | |
$startInfo = "$($mission.MissionTakenEDProfile.SystemName)/$($mission.MissionTakenEDProfile.PortName)" | |
$endInfo = "$($mission.MissionFinishedEDProfile.SystemName)/$($mission.MissionFinishedEDProfile.PortName)" | |
if ($startInfo -eq $endInfo ) | |
{ | |
$key = $startInfo | |
} else { | |
$key = "$startInfo - $endInfo" | |
} | |
$mType = "Other" | |
if ($mission.MissionType -ne $null -and $mission.MissionType -ne "") | |
{ | |
$mType = $mission.MissionType | |
} | |
if (-Not $missionInfo.ContainsKey($key)) | |
{ | |
$missionInfo[$key] = @{ | |
$mType=0; | |
} | |
} | |
$missionInfo[$key][$mType] += 1 | |
} | |
$missionDetails = "" | |
foreach($missionLocation in $missionInfo.Keys) | |
{ | |
if ($missionDetails -ne "") | |
{ | |
$missionDetails = "$missionDetails; " | |
} | |
$typeDetails = "" | |
foreach($missionType in $missionInfo[$missionLocation].Keys) | |
{ | |
if ($typeDetails -ne "") | |
{ | |
$typeDetails = "$typeDetails, " | |
} | |
$typeDetails = "$typeDetails$($missionInfo[$missionLocation][$missionType]) $missionType" | |
} | |
$missionDetails = "$missionDetails$typeDetails [$missionLocation]" | |
} | |
$timeInfo = "" | |
if ($earliestDate -eq $latestDate) | |
{ | |
$timeInfo = "$($earliestDate.ToUniversalTime().ToString("dd/MM/yyyy HH:mm"))" | |
} else | |
{ | |
$timeInfo = "$($earliestDate.ToUniversalTime().ToString("dd/MM/yyyy HH:mm")) - $($latestDate.ToUniversalTime().ToString("dd/MM/yyyy HH:mm"))" | |
} | |
$missionDetails = "$timeInfo | $missionDetails | Total reward: $totalReward cr." | |
$reportUrl = 'https://docs.google.com/forms/d/1RTM-7KUoDMBZzlsIsUIaYC7qyGVLL4ABgqeBCfo7pZc/formResponse' | |
Write-host "Report information" | |
Write-host "Commander name: $cmdrName" | |
Write-host "Number of missions: $numberOfMissions" | |
Write-host "Details: $missionDetails" | |
$form_data = @{ | |
'entry.725484914'= $cmdrName; # commander name | |
'entry.1519303364'=$numberOfMissions; # number of missions | |
'entry.150171490'= $missionDetails; # comment mission | |
'draftResponse'= @(); | |
'pageHistory' = 0; | |
} | |
$headers = @{'Referer'='https://docs.google.com/forms/d/1RTM-7KUoDMBZzlsIsUIaYC7qyGVLL4ABgqeBCfo7pZc/viewform'; | |
'User-Agent'= "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36"; | |
} | |
# Раскомментируйте если хотите увидеть что посылается до отправки | |
#Read-host | |
# send request | |
Invoke-WebRequest -Uri $reportUrl -UserAgent $userAgent -Headers $headers -Method Post -Body $form_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment