Automation of farming and tapping a hamster via Python with deployment

Friends, hello! There is incredible interest in the telegram game Hamster Kombat right now. Everyone is tapping this poor hamster in the hope that one day they will be able to sell the coins for real money. While we are all waiting, let me tell you how to automate the process of farming and tapping the hamster through Python, using one interesting project.

In conclusion of the article, I will share with you two methods that will allow us to deploy our bot remotely.

We receive a token

First, let's do some preparation. We need to get a special token for automated tapping and farming in Hamster Kombat.

  • We log in to the WEB version of Telegram: web.telegram.org

  • Open the page with Hamster Kombat.

  • Click on Play.

  • Open the developer panel (usually F12).

  • Go to the application and copy the key value tgWebAppData (screenshot with arrows below).

Installing the script

  1. Open the terminal.

  2. We enter the command (clone the project repository):

git clone https://github.com/jawikas/hamsterkombat.git
  1. Open the created directory in the IDE you are working with. In my case, it will be PyCharm.

  1. Install dependencies:

pip install -r requirements.txt
  1. Open the file tokens.txt and add the copied data from the developer panel to it. Please note that you need to add without quotes at the beginning and end of the copied line. Example:

query_id=xxxxxxxxx-Rxxxxuj&user=%7B%22id%22%3A1323733375%2C%22first_name%22%3A%22xxxx%22%2C%22last_name%22%3A%22%E7%9A%BF%20xxxxxx%22%2C%22username%22%3A%22xxxxx%22%2C%22language_code%22%3A%22id%22%2C%22allows_write_to_pm%22%3Atrue%7D&auth_date=xxxxx&hash=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  1. We perform the launch:

python main.py

Explanation of the options that will greet us

After running the script you will have the following options:

  1. Auto Buy Upgrade (Automatic purchase renewal with 3 method options) – ON OFF:

    • Upgrade items with the highest profit: Upgrade items with the highest profit.

    • Upgrade items at the lowest price (low price with high profit): Upgrade items at the lowest price (low price with high profit).

    • Upgrade items with a price less than balance: Upgrade items at a price less than balance.

  2. Auto Complete Combo (Auto-completion of daily combo) – ON OFF:

  3. Auto Complete Cipher (Automatic solution of daily Morse codes) – ON OFF:

  4. Auto Complete Tasks (Automatic task solving) – ON OFF:

  5. By default, the script performs the following actions without the need for configuration (command 5):

Now let's set the necessary settings and launch the bot.

Settings and launch

I activate all options. To start, send 5 and press ENTER:

Next, many actions will be performed and at the end we will reach a pause of 30 minutes:

After 30 minutes the actions are repeated. To stop the bot, execute the key combination CTRL + C.

To make sure that autofarming is in progress, you can open Hamster Combat from your mobile device.

After the first launch, the picture will be more pleasant for you, as several tasks will be completed automatically and several million coins will fall into your balance.

After the first launch, the picture will be more pleasant for you, as several tasks will be completed automatically and several million coins will fall into your balance.

Autofarm and autotaps in several accounts

To run multiple accounts, pass to file tokens.txt multiple tokens of tokens. Each new token must be passed on a new line:

query_id=xxxxxxxxx-Rxxxxuj&user=...
query_id=xxxxxxxxx-Rxxxxuj&user=...

In this case, all accounts will be launched, and then there will be one general pause of 30 minutes.

If you just wanted to get familiar with the project and run it from your local machine, then I have everything for you. Just figure out the settings and test their different combinations.

For those who really want to use it 24/7 – read on. There I will tell you about two ways to remotely launch this project.

Preparing for remote launch

Before launching the bot remotely, let's make some changes to the code. It is more convenient to set options at the start, thereby creating a condition under which the bot will be launched after entering the command python main.py.

Changes in config.json

{
    "min_tap": 138,
    "max_tap": 738,
    "delayUpgrade": 1,
    "DelayPerAccount": 5,
    "tapDelay": true,
    "max_price": 5000000,
    "loop": 1600,
    "auto_upgrade": true,
    "combo_upgrade": true,
    "daily_cipher_on": true,
    "tasks_on": true,
    "upgrade_method": 1
}

Here, as you can see, we have added the following parameters: auto_upgrade, combo_upgrade, daily_ciper_on, task_on and upgrade_method. In the old implementation, we specified these parameters via the terminal (1, 2, etc.).

Here is a description for each setting and their values ​​in the configuration file:

  1. min_tap: Minimum number of clicks. Used to set the lower limit of the number of clicks on the hamster.

  2. max_tap: Maximum number of clicks. Used to set the upper limit of the number of clicks.

  3. delayUpgrade: Delay before refresh (in seconds) Specifies the delay between refresh checks.

  4. DelayPerAccount: Per-account delay (in seconds) Specifies the delay between actions for each account.

  5. tapDelay: Enable/disable click delay. A boolean value indicating whether to use click delay.

  6. max_price: The maximum price that will be used when purchasing an upgrade.

  7. loop: Cycle time (in seconds). Specifies the duration of one cycle of the bot's work.

  8. auto_upgrade: Automatic Updates A Boolean value that specifies whether updates should be purchased automatically.

  9. combo_upgrade: Automatically execute combo. A Boolean value indicating whether or not to automatically execute combo actions.

  10. daily_cipher_on: Automatic execution of daily ciphers.

  11. tasks_on: Automatically execute tasks. A Boolean value that specifies whether to automatically execute tasks.

  12. upgrade_method: Update Method. Specifies the method to be used for updates. Possible values:

    • 1: Update on the highest profit.

    • 2: Upgrade at the lowest price.

    • 3: Update at a price less than the current balance.

    • Example: 1

Changes in core.py

import locale
import requests
from colorama import *
from src.utils import load_tokens
from src.auth import get_token, authenticate
from src.exceptions import upgrade_passive, claim_daily, execute, boost, clicker_config
from src.exceptions import _sync, exhausted, execute_combo, claim_cipher

from src.__init__ import (
    mrh, pth, hju, kng,
    read_config, _number, countdown_timer, log,
    log_line,
)

locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
init(autoreset=True)
config = read_config()

def main():
    auto_upgrade = config.get('auto_upgrade', False)
    combo_upgrade = config.get('combo_upgrade', False)
    daily_cipher_on = config.get('daily_cipher_on', False)
    tasks_on = config.get('tasks_on', False)
    _method = str(config.get('upgrade_method', '1'))

    cek_task_dict = {}
    countPerAccount = config.get('DelayPerAccount', 3)
    loop = config.get('loop', 3600)

    while True:
        try:
            while True:
                init_data_list = load_tokens('tokens.txt')

                for init_data in init_data_list:
                    token = get_token(init_data)
                    if token:
                        try:
                            res = authenticate(token)
                            if res.status_code == 200:
                                user_data = res.json()
                                username = user_data.get('telegramUser', {}).get('username',
                                                                                 'Please set username first')
                                log(kng + f"Login as {pth}{username}")
                                clicker_config(token)
                                clicker_data = _sync(token)
                                if 'clickerUser' in clicker_data:
                                    user_info = clicker_data['clickerUser']
                                    balance_coins = user_info['balanceCoins']
                                    earn_passive_per_hour = user_info['earnPassivePerHour']
                                    exchange_name = user_info['exchangeId']

                                    log(hju + f"Balance: {pth}{_number(balance_coins)}")
                                    log(hju + f"Income: {pth}{_number(earn_passive_per_hour)}/h")
                                    log(hju + f"CEO of {pth}{exchange_name} {hju}exchange")
                                claim_daily(token)
                                while True:
                                    exhausted(token)
                                    if not boost(token):
                                        break
                                if tasks_on:
                                    execute(token, cek_task_dict)
                                if daily_cipher_on:
                                    claim_cipher(token)
                                if combo_upgrade:
                                    execute_combo(token)
                                if auto_upgrade:
                                    upgrade_passive(token, _method)
                            log_line()
                            countdown_timer(countPerAccount)
                        except requests.RequestException as e:
                            log(mrh + f"Request exception for token {pth}{token[:4]}****: {str(e)}")
                    else:
                        log(mrh + f"Failed to login token {pth}{token[:4]}*********\n", flush=True)
                countdown_timer(loop)
        except Exception as e:
            log(mrh + f"An error occurred in the main loop: {kng}{str(e)}")
            countdown_timer(10)

if __name__ == '__main__':
    main()

Creating a Docker container

For convenience, we will create Dockerfile at the root of the project:

# Используем новый облегченный образ Python
FROM python:3.12-alpine

# Устанавливаем рабочую директорию в контейнере
WORKDIR /app

# Копируем файл requirements.txt в рабочую директорию
COPY requirements.txt .

# Устанавливаем зависимости из requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Копируем остальные файлы приложения в рабочую директорию
COPY . .

# Указываем команду для запуска приложения
CMD ["python", "main.py"]

Creating an image

docker build -t my-hamster-app .

Launching a container

docker run -it -d --name hamster-container my-hamster-app

To enter the container terminal:

docker attach hamster-container

Team docker attach hamster-container connects the current console to an already running container hamster-container. This allows you to interact with the container as if you were working directly in its terminal.

to exit CTRL + P, CTRL + Q

Deployment on VPS server

Now you can use DockerHub: upload the created image there and then download it from DockerHub to the server, or do the following:

  1. Stopping the container:

    docker stop hamster-container
  2. Remove the container:

    docker rm hamster-container
  3. Delete the image:

    docker rmi my-hamster-app
  4. Connect to the server via FTP (for example, using FileZilla).

  5. Uploading files to the server.

  1. We create an image and run the container (as in the example above).

I don't usually do this in work projects, please don't throw slippers at me. I just don't see the point in bothering with a private repository on GitHub or a repository on DockerHub in this case.

Now on the server, we repeat the same commands. I will connect via SSH with login and password:

ssh root@111.111.111.111
my_pass

Go to the created directory:

cd ../home/hamster_bot

Let's make sure all the files are in place. Now let's create the image:

The files are in place!

The files are in place!

docker build -t my-hamster-app .

If you don't have Docker installed on your server, install it (there's a lot of information on this on the Internet).

Now let's start the container:

docker run -it -d --name hamster-container my-hamster-app

Let's check if everything works:

docker attach hamster-container
76 are the first 2 characters of the container ID. You could have entered hamster-container instead of 76

76 are the first 2 characters of the container ID. You could have entered hamster-container instead of 76

Deploy to Amvera Cloud

Instead of using a VPS server with Linux and numerous configuration commands, you can use the domestic analogue of Heroku – Amvera Cloud.

Why this particular service?

I decided to tell about it because working with the Linux terminal can scare off beginners: setting up, entering commands, SSH, installing Docker, deploying files, etc. For a project like this bot, there is no point in paying 600 rubles or more, since there are practically no hardware requirements.

Amvera Cloud takes care of all the setup hassle for us, and we just need to run a few commands on our side to get our container started automatically.

In addition, to test the service, you will be given a gift balance of 111 rubles, so that you can understand whether working with this service is right for you. This will be enough for a couple of weeks of active farming and tapping your hamster.

  1. Register on the website Amvera Cloud.

  2. Let's move on to projects section.

  3. Create your first project by filling in the following fields: On the start screen, specify the project name, select “application” and choose a tariff plan. Funds are withdrawn from the balance gradually, so in the free version you can choose even the most powerful tariff. For example, I will take the simplest (trial) one.

  1. Copy the link indicated by the arrow (screenshot below).

  1. On the new screen, click Finish.

That is, we don't need to generate any settings. We've already done everything when we created our Dockerfile

Next, we'll run a few commands in our console to deliver files to Amvera. We'll initialize an empty .git directory:

git init

We link our project:

git remote add amvera https://git.amvera.ru/имя_пользователя/название_проекта

In my case it is:

git remote add amvera https://git.amvera.ru/yakvenalex/hamsterbot

When using GIT with Amvera for the first time, you may need to log in. To do this, enter your Amvera login and password in the window that appears.

Now let's upload our project files to the Amvera repository:

git add .
git commit -m "Init commit"
git push amvera master

If you get an error that the master branch does not exist, run the command:

git checkout -b master
git push amvera master
Let's check that the files have been delivered.

Let's check that the files have been delivered.

Now all that's left is to wait a couple of minutes, and our bot will be active. You can verify this by looking at your hamster or looking at the application logs.

Completion

I hope this guide was helpful and now you have an understanding of how to automate hamster farming and tapping via Python. Good luck in the game and may your hamsters bring you lots of coins!

Please support this article with a like, a subscription, or a comment if you want to continue receiving detailed analysis of unusual Python projects. See you soon!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *