Last active
January 22, 2016 21:36
-
-
Save jarig/376368fc5093f841a612 to your computer and use it in GitHub Desktop.
Elite Reporter Export settings and script for EDBoard
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, | |
[string]$username = "", | |
$password = "" | |
) | |
Write-host "User $username" | |
if ($username -eq "") | |
{ | |
$username = Read-Host "EDBoard username" | |
} | |
if ($password -eq "") | |
{ | |
$password = Read-Host -AsSecureString -Prompt "EDBoard password" | |
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) | |
} | |
# read json | |
$reportData = (Get-Content $jsonFile) | ConvertFrom-Json | |
$cmdrName = $reportData.CommanderName | |
$numberOfMissions = $reportData.Missions.Count | |
#group by system & station | |
$missionDates = @() | |
$dateToMissionMap = @{} | |
foreach($mission in $reportData.Missions) | |
{ | |
$takenTime = [datetime]$mission.MissionTakenDateTime | |
$finishTime = [datetime]$mission.MissionFinishedDateTime | |
if ($takenTime -ne $null) | |
{ | |
$missionDates += $takenTime | |
$dateToMissionMap[$takenTime] = @{ | |
"missionName" = $mission.MissionName; | |
"missionProfile" = $mission.MissionTakenEDProfile; | |
"type"="Mission Taken"; | |
} | |
} | |
if ($finishTime -ne $null) | |
{ | |
$missionDates += $finishTime | |
$dateToMissionMap[$finishTime] = @{ | |
"reward" = $mission.Reward; | |
"missionName" = $mission.MissionName; | |
"missionProfile" = $mission.MissionFinishedEDProfile; | |
"type"="Mission Finished"; | |
} | |
} | |
} | |
$missionDates = $missionDates | sort | |
$hItem = $null | |
$history = @() | |
foreach($date in $missionDates) | |
{ | |
$mission = $dateToMissionMap[$date] | |
if ($hItem -eq $null -or $hItem.system -ne $mission.missionProfile.SystemName) | |
{ | |
$hItem = @{ | |
"system"=$mission.missionProfile.SystemName; | |
"totalRewardInSystem" = 0; | |
"data"=@(); | |
} | |
$history += $hItem | |
} | |
$str = "[$($mission['type'])] '$($mission['missionProfile'].PortName)' [$($date.ToString('dd/MM/yyyy HH:mm'))] " | |
if ($mission.reward -ne $null) | |
{ | |
$str += "$($mission.reward) CR" | |
$hItem["totalRewardInSystem"] += $mission.reward | |
} | |
$str += " - $($mission.missionName)" | |
$hItem["data"] += $str | |
} | |
$loginUrl = 'http://en.ed-board.net/index.php' | |
$reportUrl = 'http://en.ed-board.net/?m=notes' | |
Write-host "Report information" | |
Write-host "Commander name: $cmdrName" | |
Write-host "Number of missions: $numberOfMissions" | |
foreach($hItem in $history) | |
{ | |
Write-host "========= $($hItem["system"]) ============" | |
$($hItem["data"] -join "`n") | |
Write-host "Total earned in the system:" $hItem["totalRewardInSystem"] "CR" | |
} | |
# login to EDBoard | |
$form_data = @{ | |
'user_name'=$username; | |
'user_password'=$password; | |
'user_rememberme'='0'; | |
'login'='Log in'; | |
} | |
Invoke-WebRequest -Uri $loginUrl -Method POST -Body $form_data -SessionVariable edSession | |
foreach($hItem in $history) | |
{ | |
$form_data = @{ | |
'id_note'=''; | |
'add_note'= $($hItem["data"] -join "<br/>") + "<br/>Total earned in the system: " + $hItem["totalRewardInSystem"] + " CR"; | |
'system'=$hItem["system"]; | |
} | |
Invoke-WebRequest -Uri $reportUrl -Method POST -Body $form_data -ContentType 'application/x-www-form-urlencoded' -WebSession $edSession | |
} |
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
Export settings for EliteReporter | |
Application->Settings | |
Executable to run on Export | |
powershell.exe | |
Arguments | |
"& ""C:\<path_to>\edboard_send_report.ps1""" -jsonFile $exportedFile | |
Optionaly you can add -username <username> -password <password> to the command above, | |
then it won't ask you for those when pressing Export button. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment