Twitch statistics bot

Explanation how my 24/7 twitch analytics bot (BotTSF) works and why I built it.

This post will be in English because I built this for the international streamers community of twitch; if anyone is interested I want them to be able to read it 🙂

I have been working on this project since the beginning of September 2020 (during the Corona period).


  1. What is it?
  2. How does it work
    1. Data collection
    2. Chatbot
    3. Graphical interface

What is it?

BotTSF is a Twitch channel; it is streaming 24/7 twitch statistics which are updated constantly. My goal with making this bot is to help starting streamers like myself get a grasp of which games/categories are over-saturated. Over-saturated means there are too many people streaming in that specific category/game.

According to nearly all search results related to growing a community on twitch mention and advice against streaming in an over-saturated game, but rarely ever define what over-saturated means and how to determine what categories are not over-saturated [1] [2].

So, why is this over-saturation a bad thing? Over-saturation could be problematic for starting streamers since Twitch orders streams by viewer count; so as a starting streamer you will end up near the bottom since you don’t really have a community built yet. So the point here is that small streamers stay small because they have only a small chance of getting noticed. I want to help people find where they can grow by giving them more information, because I know how hard I find it to determine what over-saturation means I figured others might too.

How does it work?

The complete bot consists of three separate parts; the data collection part, a chatbot, and the graphical interface. The whole thing has been inspired a lot by similar projects like Lurxx and Comanderroot.

Nearly every part of this bot is made exclusively using python. When I get around to it I will try and incorporate PHP and Javascript more as well. This project was mainly meant for me to learn and be more confident with building stuff in python but also to get a grasp at what the whole over-saturation thing truly means.

– Data Collection

For data collection I’m using the Twitch API, I build a list of all categories using the “/games/top” endpoint and with the pagination I request until I’ve reached the end of the pagination. For requesting from the API I used the python requests library, starting out I used “requests.get()” only to find out about “requests.session()” which turned out to be a little quicker.

After building the list of categories I go through the entire list, building a list of every stream for that specific category. After condensing all of this data I store what I think is important into a SQL database using the SQLITE3 python library.

– Chatbot

Originally when I just started streaming I thought it would be fun if I could build a chatbot that would link the chats of my and all of my friends their Twitch streams together. This idea kind of faded, but I still wanted to build a bot for my own channel. So I found some example python code on the great interwebs and modified it with my own custom commands (yes I know, that makes me a scriptkiddie, but its a great way to learn for a starter 😉 ) this way I became quite confident with how to do a little python with IRC.

I repurposed this bot with commands that reply with data from the SQLITE3 database whenever the user asks for anything. I made 2 commands that execute the exact same function; "!game [name]" and "!category [name]". These commands make the bot answer with the data from the database for the specified category.

I plan on making a "!sort [column_name]" command that allows for sorting and something like a "!page [number]" that allows for scrolling through the data.

– Graphical interface

The graphical interface, the part you can see on the stream is a HTML page. I am using OBS (Open Broadcaster Software) to stream. In OBS I added a browser source loading a local HTML file, which I make by filling a HTML template with data from the database using another python script (I probably should have done this with PHP/Javascript in hindsight, but I am not at all confident using these languages yet. It would make for a good learning experience tho). In this process I found a few hurdles to overcome. OBS didn’t refresh the screen when I updated the HTML file, this is where I learned you have to make the browser reload using a meta tag… (<meta http-equiv="refresh" content="[seconds]">) after this it worked flawlessly! Just for fun I decided to load a non copyright radio-stream in a second browser source in OBS as well which made the whole thing look like a bit more of a finished product.

I still want to add custom displays per category to show historic data in graphs and a more detailed view, but that is for later version.