Capturing & Analyzing online users Trend on Reddit with Powershell


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.1

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.

2

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

fetimage

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

3

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. 

4

Like in the following image

5

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 🙂

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)

6

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 :

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 🙂

signature 

Advertisements

3 thoughts on “Capturing & Analyzing online users Trend on Reddit with Powershell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s