-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateresume.ps1
64 lines (53 loc) · 1.65 KB
/
updateresume.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
param (
[Parameter(Mandatory=$true)] [string]$token
)
$base = 'https://api.hh.ru'
function Result-FromHH{
param (
[Parameter(Mandatory=$True)][string]$uri,
$method = "Get"
)
$access_token = @{
"Authorization" = "Bearer {0}" -f $token
}
try {
$result = (Invoke-WebRequest -uri $uri -method $method -Headers $access_token).Content | ConvertFrom-Json
}
catch {
$result = $false
}
return $result
}
DO
{
#Step one: Check auth token
$uri = "$base/me"
if (-not (Result-FromHH ( $uri ))) {
throw "Something go wrong, maybe your auth token failed. Check your token!"
}
$uri = "$base/resumes/mine"
foreach ( $resumeurl in $(Result-FromHH( $uri )).items.url) {
$uri = "$resumeurl"
$resumeurl = Result-FromHH( $uri )
if ((Get-date) -ge (Get-date $resumeurl.next_publish_at)){
Start-Sleep -Seconds 60
$uri = "$uri/publish"
if (-not $(Result-FromHH -uri $uri -method "POST")) {
Write-Output "Unknown answer, ignore this."
}
else {
write-output "Success, time to sleep."
}
}
else {
if ((Get-date $resumeurl.next_publish_at) -ge $time ) {
$time = $((Get-date $resumeurl.next_publish_at).AddMinutes(60))
}
}
}
write-output "Sleep until $time`. Zzzzz"
if ((New-TimeSpan -end $time).TotalSeconds -le 0) {
$time = (get-date).AddHours(1)
}
Sleep -second (New-TimeSpan -end $time).TotalSeconds
} WHILE( $true )