Skip to content

Instantly share code, notes, and snippets.

@y-ack
Created November 10, 2017 05:12
Show Gist options
  • Save y-ack/967e475b39831c00edc845a1d144459d to your computer and use it in GitHub Desktop.
Save y-ack/967e475b39831c00edc845a1d144459d to your computer and use it in GitHub Desktop.
SmileBASIC Source Log Graphing (files will be released slowly)
[Uri]$Domain = "http://scratch.smilebasicsource.com/chatlogs"
[Microsoft.PowerShell.Commands.HtmlWebResponseObject]$LogListDocument = Invoke-WebRequest $Domain
[Int32]$CurrentFileNum = 0
[Int32]$TotalFiles = $LogListDocument.Links.Count
[Regex]$DateRegexp = [Regex]'(\d\d-\d\d-\d\d)'
[Regex]$UserRegexp = [Regex]'\n *([a-zA-Z0-9_]+)\['
[String]$TAB = "`t"
[String]$UserData = "" # only users logged for each day
[String]$NumberedData = "" # includes message counts per user per day
$LogListDocument.Links | Where { $_.href -match "\.txt" } | ForEach-Object {
$CurrentFileNum += 1
[String]$WorkingData = ""
[Hashtable]$Users = [Hashtable]::new()
[HtmlWebResponseObject]$Log = Invoke-WebRequest ($Domain + $_.href)
[String]$date = $DateRegexp.Match($_.href).Value
$WorkingData += "$date;"
$NumberedData += "${date}:" + [Environment]::NewLine
Write-Output $date + " ($CurrentFileNum of $TotalFiles)"
[System.Text.RegularExpressions.MatchCollection]$UserMatches = $UserRegexp.Matches($Log.Content)
$UserMatches.Groups | where { $_.Name -eq 1 } | ForEach {
if ($Users.ContainsKey($_.Value) -eq $False) {
$Users.Add($_.Value, 1)
} else {
$Users.Item($_.Value) += 1
}
}
$UserMatches.GetEnumerator() | Sort-Object -property Value -Descending | ForEach-Object {
$WorkingData += $_.Name + ","
$NumberedData += $TAB + $_.Name + ":$TAB" + $_.Value + [Environment]::NewLine
}
$WorkingData += [Environment]::NewLine
$UserData += $WorkingData
}
$UserData | Out-File "LogData.csv"
$NumberedData | Out-File "MessageStats.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment