Closed TickleThePanda closed 2 years ago
Required 4 weeks before FAPs
Meetings to decide final FAP allocation for the proposals are on Monday 7th, with Emma's approval work can start on the 8th to split the proposals ready to add to the XFAP site.
@mutambaraf's Powershell script to download all proposals from a given round:
<#
.SYNOPSIS
Extracts the proposal documents from Proposal Submission and put them in a
specified directory grouped by Facilities Access Panel.
.DESCRIPTION
Extracts the proposal documents from Proposal Submission and put them in a
specified directory.
This uses the proposal graphQL API to find the details of
the relevant proposals and downloads.
.PARAMETER GraphqlAPIUrl
The URL of the graphql proposals submission site where the proposal information is
stored.
.PARAMETER OutputDir
The output directory of the documents. This will create the
directory and subdirectories.
.PARAMETER CallId
The round in the year for the proposals. Must be a single digit.
.PARAMETER AccessToken
Credentials to access the proposal submission site. Will be used to read the
proposal information from the api.
.PARAMETER ProposalPdfUrl
The URL to download each proposal document.
.EXAMPLE
# Input your access token
$AccessToken = Get-AccessToken
# Run the command
./Extract-ProposalsPdfs.ps1 `
-GraphqlAPIUrl "https://devproposal.facilities.rl.ac.uk/graphql" `
-OutputDir "output/Direct_2022" `
-CallId "1" `
-AccessToken $AccessToken
-CookieDomain "devproposal.facilities.rl.ac.uk"
-ProposalPdfUrl "https://devproposal.facilities.rl.ac.uk/download/pdf/proposal"
#>
Param(
[Parameter(Mandatory=$true)]
[string]
$GraphqlAPIUrl,
[Parameter(Mandatory=$true)]
[int]
$CallId,
[Parameter(Mandatory=$true)]
[string]
$OutputDir,
[Parameter(Mandatory=$true)]
[string]
$AccessToken,
[Parameter(Mandatory=$true)]
[string]
$CookieDomain,
[Parameter(Mandatory=$true)]
[string]
$ProposalPdfUrl
)
Write-Host "Start"
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
# Generate URL
$URL = $GraphqlAPIUrl
try{
Write-Host "Generatings access cookie"
$Cookie = New-Object System.Net.Cookie
$Cookie.Name = "token" # Add the name of the cookie
$Cookie.Value = $AccessToken # Add the value of the cookie
$Cookie.Domain = $CookieDomain
$Cookie.Secure = 0
$WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$WebSession.Cookies.Add($Cookie)
Write-Host "Cookie successfully created"
}catch {
Write-Error -Exception $_.Exception -ErrorAction Stop
}
try{
Write-Host "Parse token to request header"
$headers = @{
"Authorization" = "Bearer $($AccessToken)"
"Content-Type" = "application/json"
}
Write-Host "Header created successfully"
}catch {
Write-Error -Exception $_.Exception -ErrorAction Stop
}
try{
Write-Host "Generating proposals query"
$bodytxt = @{"query" =
"query {
proposals(filter:{callId:$CallId}){
totalCount
proposals{
proposalId
primaryKey
call{
shortCode
}
proposer{
lastname
}
}
}
}
"
} | ConvertTo-Json
Write-Host "Request query created successfully"
}catch {
Write-Error -Exception $_.Exception -ErrorAction Stop
}
try{
Write-Host "Creating output folder"
New-Item $OutputDir -Force -ItemType Directory | Out-Null
Write-Host "Output folder created successfully"
}catch {
Write-Error -Exception $_.Exception -ErrorAction Stop
}
try {
#Make request and get proposals
Write-Host "Fetching proposals from $URL"
$Response = Invoke-RestMethod -Uri $URL -Method Post -Headers $headers -Body $bodytxt
$TotalProposalsCount = $Response.data.proposals.totalCount
Write-Host "Total proposal to download $TotalProposalsCount"
}catch {
Write-Error -Exception $_.Exception -ErrorAction Stop
}
try {
Write-Host "Fetching proposals pdfs from $ProposalPdfUrl"
$Proposals = $Response.data.proposals.proposals
Write-Host "response $gqlResponse"
ForEach ($Proposal in $Proposals) {
$ProposalId=$Proposal.proposalId
$ProposalKey=$Proposal.primaryKey
$ProposaserLastname=$Proposal.proposer.lastname
Write-Host "Proposal details Proposal Id: $ProposalId Key: $ProposalKey Proposer lastname: $ProposaserLastname "
$ProposalDocumentUrl = "$ProposalPdfUrl/$ProposalKey/"
Write-Host "Fetching proposal pdf from $ProposalDocumentUrl"
Invoke-RestMethod -Uri $ProposalDocumentUrl -Headers $headers -WebSession $WebSession -OutFile $OutputDir/$ProposaserLastname'_'$ProposalId'.pdf'
Write-Host "Proposal pdf for id: $ProposalId key: $ProposalKey proposer lastname $ProposaserLastname successfully "
}
}
catch {
Write-Error -Exception $_.Exception -ErrorAction Stop
}
Write-Host "Proposal documents from proposal submission downloded successfully"
Write-Host "End"
Agreed as finished at sprint planning.
Part of https://github.com/UserOfficeProject/stfc-user-office-project/issues/11
The ISIS FAP results are currently stored in the online XFAP site.
We need to:
Note that proposals that are assigned a FAP with underscores (e.g. "FAP1_FAP2_FAP3") will need to be included in all of the FAPs listed.