Python "Hello Bot"¶
Warning
This tutorial uses a old version of the project template offered by BotCity.
If you've used this template before and have any questions, you can continue using this guide as normal.
If you are starting with Python automations, we strongly recommend using the new version of the project template.
This tutorial will guide you through the process of creating a simple Python automation.
Prerequisites¶
- BotCity Account
- BotCity Studio SDK
- Python 3.7 or higher
Creating Your First Project¶
BotCity offers a template project which can be customized via a tool called cookiecutter.
Installing Cookiecutter¶
In order to use it we need first to install the cookiecutter Python package by running the following command on your command-line terminal:
python -m pip install --upgrade cookiecutter
After doing that you are ready to create your first Python automation using BotCity’s framework.
From Template to Project¶
With cookiecutter properly installed, it is time to make use of it and create a new project.
To create a new project using our template we will invoke the cookiecutter and provide as argument the URL in which the templates from BotCity is located:
The system will prompt you with a couple of answers in order to properly create your project.
- Once prompted for project_type answer with 1 for Desktop and press enter;
- For bot_id type
HelloBot
and press enter; - Under project_name type
Hello Bot
and press enter; - For project_short_description type
My first project with BotCity
and press enter.
Info
More information about the project types and options can be found on the Template project documentation website.
After going through the process above you will now have a new folder named HelloBot
.
Success
Congratulations, you now have a project with BotCity’s Python framework. 🏆
Let’s take a deeper look into it.
Exploring the Project¶
Under your project folder HelloBot
you will have the following structure:
HelloBot
├── MANIFEST.in <- This file defines the content of the package.
├── README.md <- Simple README file for your bot project.
├── VERSION <- This file defines the Bot package version.
├── HelloBot <- Main module for your Bot package.
│ ├── __init__.py
│ ├── __main__.py <- Entrypoint for the module.No need to bother with this file.
│ ├── bot.py <- Here is where you will develop your bot code.
│ └── resources <- Folder containing resources useful for the Bot.
├── build.bat <- Batch script to generate the package
├── build.sh <- Shell script to generate the package
├── requirements.txt <- File describing the python dependencies for your Bot.
└── setup.py <- Setup file for the package.
Note
It may seem like a lot of files and folders but here are the most important ones:
- bot.py: Change this file and add here the code for your bot.
- resources: Add into this folder files to be used with your bot such as images, spreadsheets and etc.
- VERSION: Change the content of this file when updating the version of your bot. It is recommended to use versions in the format X.Y. E.g. 1.0, 1.1, 2.5, 3.10.
Great!
All this information is great but it is time to see some action.
Let’s test this shiny new Bot locally. 🦾🤖
Testing Your Project Locally¶
In order to test our project locally, let’s first install it so we can have all the Python dependencies ready.
Using the command-line tool, access the HelloBot
folder which we described above.
Installing the Project¶
From this folder run the command below to install your project on development mode:
Pro Tip
Installing using the development mode flag -e
makes it so that we can keep developing and running our Bot without the need to reinstall it.
This command will produce a lot of output which means that all dependencies such as botcity-framework-core
, and others are being installed.
Once this process is over, you should see an output similar to this one:
<... other output from installation ...>
Running setup.py develop for HelloBot
Successfully installed HelloBot-1.0 ...
The important message here is the Successfuly installed HelloBot-1.0
.
This means that your project is now ready to be executed.
Running the Bot¶
Our template project runs a very simple automation. It opens up your default web browser and loads BotCity’s website.
You can execute your HelloBot
with the following command:
Here is a screenshot of the expected result:
🌟 Excellent 🌟
You are now ready to start creating automations using the BotCity’s Python Framework.
Conclusion¶
Under this tutorial you learned:
-
The dependencies required to develop automations using BotCity’s Python framework and how to get them installed.
-
How to create new Bot projects using cookiecutter and BotCity’s template.
-
How to install and run your new Bot project locally.
Have fun automating 🤖
Next Steps¶
Now it is time to load your project with BotCity Studio and start creating your automations with Computer Vision and all the productivity offered by our tool.