PoshCode Archive  Artifact [ada6afb5c5]

Artifact ada6afb5c5b68381784c8580d48afce6c3ec5824635c0f432c9b0c733b743b0c:

  • File Factorio-blog-alert.ps1 — part of check-in [3913e646e3] at 2018-06-10 14:15:12 on branch trunk — This script plays beep sound when there is new post at Factorio blog. Converted from JS original – https://gist.github.com/demipixel/1a5a42022c24d88de1308a934bd78246 by demipixel. (user: Xaegr size: 1207)

# encoding: ascii
# api: powershell
# title: Factorio blog alert
# description: This script plays beep sound when there is new post at Factorio blog. Converted from JS original – https://gist.github.com/demipixel/1a5a42022c24d88de1308a934bd78246 by demipixel.
# version: 0.1
# type: function
# author: Xaegr
# license: CC0
# x-poshcode-id: 6407
# x-archived: 2016-06-29T10:16:36
# x-published: 2016-06-27T11:59:00
#
#
$AlertOnErrors = $false
$LastGid = '250329347071682810'
$Interval = 60 # Seconds
$URI = 'http://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=427520&count=3&maxlength=300&format=json'

$client = New-Object System.Net.WebClient

function Check()
{
    try 
    {
        $data = $client.DownloadString($URI)
        $json = ConvertFrom-Json $data
        $currentGid = $json.appnews.newsitems[0].gid
    }
    catch
    {
        Write-Warning "Error: $_"
        if ($AlertOnErrors)
        {
            return $true
        }
    }
    return ($currentGid -ne $LastGid)
}

while (1)
{
    if (Check)
    {
        Write-Warning "ALERT!!!"
        [System.Console]::Beep(1000,1000)
    }
    
    sleep -Seconds $Interval
}