Get-UsersOnlineOnReddit.ps1
<#PSScriptInfo
.VERSION 1.0.0 .GUID 5993de12-7f7e-4ed7-ba83-a09b39e0bc59 .AUTHOR PrateekSingh .COMPANYNAME .COPYRIGHT .TAGS Powershell reddit WebScraping Automation AWS .LICENSEURI .PROJECTURI https://geekeefy.wordpress.com/2017/03/22/pumping-reddit-user-trend-to-aws-cloudwatch-with-powershell/ .ICONURI .EXTERNALMODULEDEPENDENCIES AWSPowershell .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Script to web data scrape reddit user trend and pump all the data points script captured from Reddit’s Powershell Community page to AWS Cloud Watch (AWS monitoring solution) #> Initialize-AWSDefaults -Region us-west-2 ` -AccessKey YOUR_ACCESS_KEY ` -SecretKey YOUR_SECRET_KEY Function Get-UsersOnlineOnReddit { $OnlineUsers = (Invoke-WebRequest https://www.reddit.com/r/PowerShell/).ParsedHtml.all | ` Where-Object{ $_.classname -eq "users-online fuzzed" } | ` ForEach-Object { ($_.innertext -split " " -replace "~","")[0] } If($OnlineUsers) { $data = New-Object Amazon.CloudWatch.Model.MetricDatum $data.Timestamp = (Get-Date).ToUniversalTime() $data.MetricName = "Online Users" $data.Unit = "Count" $data.Value = $OnlineUsers Write-CWMetricData -Namespace "Usage Metrics" -MetricData $data } } $i = 1 While($true) { Get-UsersOnlineOnReddit Start-Sleep -Seconds 30 Write-Host "$i data point recorded on AWS CloudWatch" $i = $i + 1 } |