PYTHON MONEY
Open in Telegram
1 903
Subscribers
No data24 hours
+17 days
+630 days
Posts Archive
1 903
At this stage, we have created the structure of our bot and the class hierarchy.
The next step is to create the skeleton of our classes and the bot's launch logic.
1 903
Take note of the module structure above.
For each class, we’ve created a separate .py file (module).
Don’t think that only one class can be created in a single .py file.
You can also create additional classes in the same file if they are closely related to the task of the main class.
So, the recommendation is:
One file — one task.
This makes the code easier to read and maintain.
1 903
Where will we store our classes? We'll create a package called modules, and inside it, we’ll create a .py file for each class.
Additionally, we’ll create a main.py file in the root of the project. This file will serve as the entry point to the application and will contain the logic for launching the different modes of the bot.
We’ll also need a data folder in the bot, where various global project files can be stored, such as the keyfile.json file for integrating the bot with Google Sheets.
Thus, our project structure will look like this.
We created a similar bot structure in lesson 4 of the Pinterest Money course. In that lesson, you’ll also learn how to build a prompt builder, and connect the bot to Google Sheets.
1 903
⬆️ This architecture will be sufficient for our project.
We could also build the architecture using interfaces, abstract classes, and contracts, but I don't want to overcomplicate things or overload you with information right now.
I can explain this separately in the future, but for now, this architecture will be enough.
1 903
Since the process and results of the work of each of our classes depend on the project folder, we see that all our classes have a common element — the project working directory.
In addition to this, different classes may have other common functionality, such as reading or writing data to CSV files or a database.
To avoid code duplication (the DRY principle) and to facilitate project maintenance, let's use inheritance to extract the common elements of our child classes into a separate parent class (base class).
Thus, we introduce an additional class, which we will call BaseGenerator.
We will inherit our classes from this base class, allowing us to access its attributes and methods from the child classes.
Therefore, our inheritance hierarchy looks like this.
1 903
Not 150 yet, but still not bad. Let's continue.
What characteristics should our bot have?
First of all, it should support multiple projects.
This means its folder structure should look something like this.
1 903
After our classes are defined, it’s time to:
1. Create the bot’s basis
2. Plan the folder and file structure of the project
150 fires 🔥 on this post, and we’ll continue.
1 903
So, let’s take another look at our potential classes and consider their responsibilities.
1. Writing the script - ScriptWriter
2. Dividing the script into scenes - ScriptDivider
3. Writing prompts to generate images for each scene - PromptsWriter
4. Generating AI images - ImageGenerator
5. Downloading video footage from stock - FootageDownloader
6. Generating voiceovers - VoiceGenerator
7. Generating the video - VideoGenerator
We can definitely say that each of the classes — ScriptDivider, ImageGenerator, FootageDownloader, VoiceGenerator, and VideoGenerator — has its own distinct responsibility. Each class performs its specific task, aligning with the SRP principle.
What about the ScriptWriter and PromptsWriter classes? At first glance, it might seem that their responsibilities overlap (writing text), and we could combine these two classes into a single Writer class without violating SRP.
In reality, these classes deal with different aspects of text, and their roles do not overlap. Each has its own distinct task. Therefore, it’s correct to keep these classes separate, which will align with the SRP principle.
Thus, our list of classes looks like this:
1. ScriptWriter
2. ScriptDivider
3. PromptsWriter
4. ImageGenerator
5. FootageDownloader
6. VoiceGenerator
7. VideoGenerator
1 903
SRP. The first principle of SOLID.
This principle states that a class should perform a specific task and should not be overloaded with other unrelated tasks.
Just as a function should execute only one complete task, this principle applies to classes as well.
However, unlike functions, it’s harder to define the boundary of violating this principle with classes.
So, use common sense and avoid extremes:
1. Don’t create classes that do too much (the God Object anti-pattern).
2. But also, creating a multitude of classes with just one method inside may also not be the best practice.
...
1 903
Next, we need to define the classes of our bot. Here are a couple of simple rules to help with that.
For this, we need to:
1. Identify the actors
2. Consider the Single Responsibility Principle (SRP)
An actor is an entity that interacts with the system or performs certain actions within the system. For example, Writer, Downloader, Generator, etc.
Let’s take our task decomposition and match each point to the corresponding actor.
1. Writing the script - ScriptWriter
2. Dividing the script into scenes - ScriptDivider
3. Writing prompts to generate images for each scene - PromptsWriter
4. Generating AI images - ImageGenerator
5. Downloading video footage from stock - FootageDownloader
6. Generating voiceovers - VoiceGenerator
7. Generating the video - VideoGenerator
In the next post, we will analyze our potential classes in terms of SRP.
1 903
Let's get started. We can base our Shorts bot on the Shorts creation technology described by 10x income in this video.
Where should we start when implementing such a complex task? With decomposing the task into smaller steps.
In our case, the initial decomposition might look like this:
1. Writing the script
2. Dividing the script into scenes
3. Writing prompts to generate images for each scene
4. Generating AI images
5. Downloading video footage from stock
6. Generating voiceovers
7. Generating the video
In the future, these steps could become separate modes of the bot. In the end, we will also create a unified mode that will combine the entire pipeline.
Next, we need to determine what classes will be present in our bot.
* The goal of this series of posts is to share experience, rather than promote any paid course.
1 903
Good. I see your interest. 😊
Let's do this. 100 fires 🔥 on this post, and I'll run a free mini-course right here on Telegram on how to write Shorts Monster
1 903
Is it difficult to implement what I showed above?
I can teach you how to do the same in just a few posts here.
🔥 - I want this
1 903
Workflow for generating viral Shorts/Tiktoks. Prompt builder. Google Sheets. Control Panel.
🔥 - I want to see the continuation and the result of the work
1 903
4. THE BEST WAY: Learning and Applying Something New
All the previous methods are good, but there is no better brain training than learning and applying something new.
If you constantly read, it becomes routine for the brain. If you constantly do calculations, it becomes routine. It becomes boring, and a new growth point is needed.
The growth point is learning and applying something new. That's when the brain starts to wake up.
It doesn't matter what it is: learning a new language, a programming language, studying painting, playing the piano, or creating a new earning scheme.
What matters is that it resonates with you and is not a form of violence against yourself.
