Introduction: Instructable Hit Announcer Bot
In this instructables I will show you how to make a simple Python bot that alerts you when your instructable (your tutorial) gets more views.
This Python bot's user interface is a command line app.
When you get an increased quantity in views, it will beep, display an alert visually, and speak the announcement!
You can customize the minimum view increase interval.
I've included two bonus scripts. The first sends you a notification email instead of text-to-speech, and the other script allows you to customize the notification ringtone.
NOTICE: These Python scripts may no longer work someday if instructables.com modifies their API, or if Google changes their captcha regulations. We will try to update this tutorial with a fix if that happens!
Step 1: Watch the Video
The video contains a full step-by-step tutorial.
If you prefer reading instead of watching, the rest of this instructable is just for you.
Step 2: Get the Files
Step 3: Install Python and Add to Path
Open up the python installer you just downloaded.
Click install, but make sure to check the checkboxes that say "Add Python to PATH" and "Install Pip"!
Step 4: Install the Required Python Libraries
Open up your computer's command prompt terminal. On my Windows PC, this is done by going to Start, then typing in "CMD", clicking the "CMD" app to open it up.
2. In the command prompt, type in each of the following commands, hitting enter between them:
pip install requests pip install time pip install gtts pip install pyfiglet pip install colorama pip install num2words pip install simpleaudio pip install smtplib pip install time
This will install the necessary libraries.
Step 5: If You Want Email Notifications
If you decide to use the alternative script that sends email notifications, you will need to configure your Gmail account to enable "allow less secure apps".
While logged into your gmail at gmail.com, go to https://myaccount.google.com/security
Scroll down to the part that says "Allow less secure apps"
Turn ON "allow less secure apps".
If you don't want to make your main gmail less secure, or if you don't already have gmail, then sign up for a new gmail solely for this purpose.
Step 6: Run the Python Bot!
Open up command prompt the same way you did earlier.
CD into the location of the python script folder you already downloaded and unzipped from the Maker Saga website, and type in cd ____ with the path to the python script replacing the blank line.
For example, on my laptop the command is
Hit enter, then type in "py" followed by the name of the Python bot script.
or for the email notification version
or for the custom ringtone version
then hit enter.
The command line app will now load, and it will prompt you for your info.
Step 7: Configure the Python Bot
The bot will ask you for the stats JSON link from your instructables tutorial page.
It is not the main URL to your tutorial, so you will need to get it by...
- Go to your instructable page in Google Chrome,
- Right click, and select inspect.
- Click the Network tab
- In the search box called "filter", type in "Stats"
- Reload the page.
- Look for the item called "getIbleStats"
- Right click the getIbleStats and select Copy->Copy Link Address.
- That is the Stats JSON URL for your tutorial. Paste in into the bot command line app when it prompts you for it.
- Follow the rest of the prompts from command line bot.
- The bot will now scan for views (hits) on a loop and alert you whenever you want!
I found this URL by looking at a cookie called "categoryTimer" that instructables.com loads when you visit their site. It contained a unique ID that was also inside the unofficial JSON API which I found searching the HTTP requests using that ID that occur when any instructable is loaded in Chrome. I might be possible that the JSON URL expires after several hours, and would cause the bot to stop working.
I've ran a bot for more than 10 hours without any hiccups, so I don't think you will encounter hiccups either.
Step 8: How It Works
In case you're curious how the python bot works, I will try my best to explain.
- The bot first takes setup info from the user
- The bot pulls the view count info from instructables
- the bot pauses for 20 seconds to wait for changes
- the bot pulls the newer view info from instructables again.
- If the newer view count is greater than the older view count by the interval the user set, it plays an alert sound, speaks the announcement, displays the info visually, and/or sends an email alert.
- If not, it rescans until it is true.
- The bot loops, repeating this process.
The lines that say "import" simple pull in the Python libraries that the script needs in order to work.
This one imports a library for custom fonts:
from pyfiglet import Figlet
This one imports a library for Gmail integration:
This one is for timing delays:
This one if for playing custom .WAV audio ringtones:
import simpleaudio as sa
This one is for custom font highlighting and colors:
This one is for pulling the view count of a instructable from the internet
This one is for the robot speaking aloud text (like Siri) using Google text-to-speech engine:
This one is for to text to speech to say large numbers naturally:
For example, with num2words, "1999 views" is spoken as "nineteen thousand ninety nine views".
Without num2words, "1999 views" is spoken as "one nine nine nine views".
This line ask for input input and stores it in a variable called "messageappend". Think of variables as nicknames for storing information for accessing later on. The setup portion of the script has a variable for each question prompt.
messageappend = input('What is the title of the instructables tutorial you want to monitor?\n')
The "\n" part just adds a new line for spacing.
There are "While Loops" and "If Loops" too. These parts run over and over again while a condition is true, and stop otherwise. Everything inside a loop is indented by 4 spaces.
This part below takes the URL store in the variable "idlink" and uses requests.get to pull the contents of that link from the internet. Then it identifies the contents as a JSON array. It then pulls the contents of the array key "views" which is the number of views into the variable "viewz", and converts the number inside "viewz" to an integer instead of the data type it was before. "Viewz" is also converted into a string data type called "oldviewsstr"
r = requests.get(idlink) jsonstring1 = r.json() viewz = jsonstring1['views'] oldviews = int(viewz) oldviewsstr = str(oldviews)
In case you were wondering, a JSON array looks like this:
time.sleep(20) pauses the bot for 20 seconds.
This part makes a beeping alert noise:
This part saves the text to speech file under a new name each time to avoid errors:
x = ['jim', 'john', 'josh'] tts = 'tts' for i in range(0, 3): tts = gTTS(text = speek, lang = 'en') file1 = str('hello' + str(i) + '.mp3') tts.save(file1)
That's the gist of it!
Step 9: That's All!
I hope you enjoyed this instructable!
We have a be nice policy.
Please be positive and constructive.