A bot that post the first comment on every new video of specified channels.
MIT License
A bot that leaves the first comment on every new video of specified channels.
DISCLAIMER: This project is built for educational purposes. DO NOT use it to create spam-bots.
Current modules:
comments
table in the DB withchannels
table in the DB with URLs to the Channels'These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
You need to have a machine with Python >= 3.8 and any Bash-like shell (e.g. zsh) installed.
$ python3.8 -V
Python 3.8
$ echo $SHELL
/usr/bin/zsh
This project requires a MySQL database and a YouTube API key. Optionally, you can also set up a Dropbox API key which is very useful when you use Heroku to deploy the bot.
References:
This section will go through the installation steps, setting up the configuration files and comments, and preparing the DB tables.
All the installation steps are handled by the Makefile. By default, it uses conda
environments. If you want to use virtualenv
instead, append to every make
command the flag:
env=venv
. If you want to modify the name of the environment or use another python version, modify the
first lines of the Makefile.
Deactivate and active Conda environment, install the requirements and load the newly created environment:
$ conda deactivate
$ make install
$ conda activate youbot
The project uses YML config files along with command-line arguments. There are three configs I am using:
commenter
command
max_posted_hours
option to 1 and increase it the next daysaccumulator
commandI am not going to go into depth for each available setting because you can use the three YML files as
templates. The only thing that should be mentioned is that I am using environmental variables to set
most of the values. For example: db_name: !ENV ${MYSQL_DB_NAME}
. You can replace
the !ENV ${MYSQL_DB_NAME}
part with the actual value, for example: db_name: My_Database
. For more details on how to use env
variables check these instructions.
Now, you don't want the bot to post the same comment over and over again. For that reason, I am using a
pool of available comments, and the bot automatically picks one that hasn't been commented on to the
respective channel yet, otherwise, it picks the one that was posted the longest time ago. Just create
a default.txt
file in a folder named comments
and write one comment per line. If, for a specific
channel, you want to have additional comments, create another txt file named after the channel's id.
For example, you can create a UC-ImLFXGIe2FC4Wo5hOodnw.txt
for the Veritasium YT channel that
has that id.
We are now ready to add YT channels to our following list (stored in the DB). After ensuring you are in the Conda environment, use the following command to add channels:
Using the channel ID
$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m add_channel -i <channel id>
Using the channel username (Fails most of the time)
$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m add_channel -u <channel username>
To view the followed channels run:
$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m list_channels
Similarly, to remove a channel run:
$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m remove_channel -i <channel id>
There is also the option to set the priorities of each channel. If 2 or more channels post videos at the same time, the bot will leave comments first to the ones with the highest priority value. To do so run the following:
$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m set_priority --priority <priority num> -i <channel id>
After you're done, you can optionally populate the table with each channel's profile picture:
$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m refresh_photos
Now we are ready to run the commenter module of the bot. Assuming you set up the channels, created the configuration, and you have the comments ready, run the following command:
python youbot/run.py -c confs/commenter.yml -l logs/commenter.log -m commenter
The bot will then run indefinitely until you stop it.
You can view all the comments posted at any point with the following command:
python youbot/run.py -c confs/generic.yml -l logs/generic.log -m list_comments --n-recent 10
Now that the bot is running, you probably want to gather statistics about the comments such as the
number of likes and replies. There is another bot for that job, that also runs indefinitely and
constantly updates the data in the comments
table. To start it run the following command:
python youbot/run.py -c confs/accumulator.yml -l logs/accumulator.log -m accumulator
There is the option to also incorporate dropbox in the whole pipeline. Assuming you already created an API key and added a cloudstore section in the config, you can use the following options:
load_keys_from_cloud: true
(under youtube config): If set to true, the bot will automatically copykeys_folder_path
setting (in cloudstore config) to the definedkeys
setting (in youtube config). This is very useful if you deploy the bot to Heroku which isupload_logs_every: 15
(under cloudstore config): If you configured the cloudstore config for thelogs_folder_path
While: True
loops in the commenter function. Again, very useful for keeping the logs whilecomments: type: dropbox
: If you set the type of the comments
setting as dropbox
then thedropbox_folder_name
into local_folder_name
While: True
loop in the commenter. Useful for modifying the comments when running onThe deployment is being done to Heroku. For more information, you can check the setup guide.
Make sure you check the defined Procfile (reference) and that you set the appropriate environmental variables (reference).
For the continuous integration, the CircleCI service is being used. For more information, you can check the setup guide.
Again, you should set the appropriate environmental variables (reference) and for any modifications, edit the circleci config.
Read the TODO to see the current task list.
This project is licensed under the MIT License - see the LICENSE file for details.