INTRODUCTION :
Well if you write a blog and share your content on variety of social media websites and forums/communities craving maximum interaction on your content, you must have at some point in time have thought about “Man what is the best time to share my content!” early in the morning, after Lunch or at midnight.
Honestly, for me, it works after dinner around 8-9 PM IST on Facebook and Twitter. But I try them on different times just to see what might work, so in order to have that understanding for Reddit, a small idea struck me to get a trend of online users on Reddit
THE IDEA:
When you visit to Reddit’s PowerShell page you’ll find a small section at the right-hand side which shows the Number of people who had subscribed the Powershell channel and no. of users currently online as marked in the following image.
Myself being a huge fan of Web Scraping thought to capture this information of the number of online users from the web page on a for a small (not very small) sampling interval (every 10 mins for me) and save the data to a CSV file for a duration of a day or two to just see and understand user trend.
OK, so after inspecting the web page I found that all the data was residing in a Paragraph Tag <P> inside the HTML source code of the web page, now next step is to Web request this page and filter out our target paragraph, luckily it has a Unique class name “users-online fuzzed” that differentiates it from other <P> Tags.
So, using a simple Invoke-WebRequest to the Reddit page and filtering out the HTML tag using the unique class name I got the number of online users on reddit page
Now we need to extract the exact numbers and save them in the CSV file with a timestamp and wrap my PowerShell code in a function, like below
HOW TO RUN:
Schedule this script using the Task scheduler or straight away use below piece of code to run an instance of PowerShell console to start capturing the data points for you, with the TimeStamps.
Like in the following image
I let the script run for more than two days (Tue, Wed, Thur) and it captured about 300 Data points, one every 10 minutes since I started the script.
After two days I looked into the CSV data and plotted a graph and as I expected I saw a common user behavior or you can say a trend 🙂
Most of the users were online during 0300 to 0400 hours IST, now that’s some awesome geeking out I like 😀 . Imagine the beautiful conclusions made using such data trends if we allow it run and capture data point for a month or a year, isn’t it?
In the following image most of the peak data point are around 3 AM in the morning, IST (Indian Standard Time)
You can also download this CSV file using below commands on your machine and take a loot or plot a graph yourself or rather choose running the script and to capture data on your machine.
Invoke-WebRequest "https://tinyurl.com/zj4opg5" -OutFile RedditUserTrend.csv -Verbose
SCRIPT :
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) | |
{ | |
''|Select-Object @{n='Timestamp';e={(Get-Date).DateTime}},@{n='OnlineUsers';e={"$OnlineUsers"}} |` | |
Export-Csv C:\Data\RedditUsersTrend.csv -Append -NoTypeInformation | |
} | |
} | |
#$i = 1 | |
#0..500|ForEach-Object{ | |
# Get-UsersOnlineOnReddit | |
# Start-Sleep -Seconds 600 | |
# Write-Host "$i values recorded" | |
# $i = $i + 1 | |
#} | |
#Clear-Host |
NOTE:
I’m not trying to make any statements here like, the trend tell us this would be the best time for publishing your content/Questions/Information on Reddit, but who knows what might work! so we gotta keep trying 😉 I myself will try and post during the timeframe from my data analysis and see what happens, I won’t mind if am wrong.
Hoping you liked today’s geeking out and find it useful! Please share your feedback and Thank you so much for stopping by 🙂
[…] on March 8, 2017 submitted by /u/Prateeksingh1590 [link] [comments] Leave a […]
LikeLike
[…] For fun: Capturing & Analyzing online users Trend on Reddit with Powershell […]
LikeLike
[…] blog post is in continuation of my last blog post Capturing & Analyzing online users Trend on Reddit with Powershell . According to the advice from one of the best IT pros I know – Trevor Sullivan (Twitter […]
LikeLike
[…] blog post is in continuation of my last blog post Capturing & Analyzing online users Trend on Reddit with Powershell . According to the advice from one of the best IT pros I know – Trevor Sullivan (Twitter […]
LikeLike
[…] Capturing & Analyzing online users Trend on Reddit with Powershell […]
LikeLike
[…] blog post is in continuation of my last blog post Capturing & Analyzing online users Trend on Reddit with Powershell . According to the advice from one of the best IT pros I know – Trevor Sullivan (Twitter […]
LikeLike
[…] blog post is in continuation of my last blog post Capturing & Analyzing online users Trend on Reddit with Powershell . According to the advice from one of the best IT pros I know – Trevor Sullivan (Twitter […]
LikeLike