From c5d3a8a7d3845cdee95083b558c4a81f2f918738 Mon Sep 17 00:00:00 2001 From: Eyn Date: Wed, 17 Jul 2024 10:54:50 +0300 Subject: [PATCH 1/2] Refactor delay time --- bots/tapcoins/client.py | 35 ++++++++++++++++++++++++++++++++--- bots/tapcoins/strings.py | 1 + 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/bots/tapcoins/client.py b/bots/tapcoins/client.py index b7fdd78..f956e13 100644 --- a/bots/tapcoins/client.py +++ b/bots/tapcoins/client.py @@ -1,10 +1,11 @@ +import random from time import time from bots.base.base import BaseFarmer from bots.tapcoins.strings import HEADERS, URL_INIT, URL_LOGIN, URL_COLLECT, URL_CARDS_CATEGORIES, URL_CARDS_LIST, \ MSG_CURRENT_BALANCE, URL_CARDS_UPGRADE, URL_LUCKY_BOUNTY, MSG_NO_CARDS_TO_UPGRADE, MSG_SORTING_CARDS, \ MSG_CARD_UPGRADED, MSG_NOT_ENOUGH_COINS, MSG_CARD_UPGRADED_COMBO, URL_DAILY, URL_DAILY_COMPLETE, \ - MSG_LOGIN_BONUS_COMPLETE + MSG_LOGIN_BONUS_COMPLETE, URL_USER_INFO DEFAULT_EST_TIME = 60 * 45 @@ -13,6 +14,7 @@ class BotFarmer(BaseFarmer): name = "tapcoinsbot" token = None balance = None + hours_earnings = None extra_code = 'ref_QjG2zG' initialization_data = dict(peer=name, bot=name, url=URL_INIT, start_param=extra_code) @@ -38,8 +40,28 @@ def authenticate(self, *args, **kwargs): self.is_alive = False def set_start_time(self): - est_time = DEFAULT_EST_TIME - self.start_time = time() + est_time + try: + cards = self.get_cards() + if not cards: + self.log(MSG_NO_CARDS_TO_UPGRADE) + return + + self.log(MSG_SORTING_CARDS) + + cards = sorted(cards, key=lambda x: x['upgrade_earnings'] / x['upgrade_cost'], reverse=True) + + self.get_balance() + self.get_hour_earnings() + + earnings_per_second = round(self.hours_earnings / 3600) + + first_card = cards[0] + time_to_upgrade = round(first_card['upgrade_cost'] / earnings_per_second) + random.randint(60, 120) + + self.start_time = time() + time_to_upgrade + except Exception as e: + est_time = DEFAULT_EST_TIME + self.start_time = time() + est_time def get_balance(self): data = { @@ -157,6 +179,13 @@ def daily_bonus(self): self.log(MSG_LOGIN_BONUS_COMPLETE.format(step=i)) break + def get_hour_earnings(self): + + response = self.post(URL_USER_INFO, {'_token': self.token}) + data = response.json()['data'] + + self.hours_earnings = data['hour_earnings'] + def farm(self): self.get_balance() self.daily_bonus() diff --git a/bots/tapcoins/strings.py b/bots/tapcoins/strings.py index fa5faab..49be803 100644 --- a/bots/tapcoins/strings.py +++ b/bots/tapcoins/strings.py @@ -7,6 +7,7 @@ URL_CARDS_CATEGORIES = 'https://api.tapcoins.app/mine/category/list' URL_CARDS_UPGRADE = 'https://api.tapcoins.app/mine/upgrade' URL_LUCKY_BOUNTY = 'https://api.tapcoins.app/mine/lucky' +URL_USER_INFO = 'https://api.tapcoins.app/mine/mine' HEADERS = { 'Accept': 'application/json, text/plain, */*', From 25c7ed7ce1433ae7dfd7b2b1ba097738686a5a1e Mon Sep 17 00:00:00 2001 From: Eyn Date: Wed, 17 Jul 2024 11:46:04 +0300 Subject: [PATCH 2/2] Add settings: buy upgrades, upgrades count --- bots/tapcoins/client.py | 109 ++++++++++++++++++++++----------------- bots/tapcoins/config.py | 2 + bots/tapcoins/strings.py | 4 +- 3 files changed, 65 insertions(+), 50 deletions(-) create mode 100644 bots/tapcoins/config.py diff --git a/bots/tapcoins/client.py b/bots/tapcoins/client.py index f956e13..fd6359d 100644 --- a/bots/tapcoins/client.py +++ b/bots/tapcoins/client.py @@ -2,10 +2,11 @@ from time import time from bots.base.base import BaseFarmer -from bots.tapcoins.strings import HEADERS, URL_INIT, URL_LOGIN, URL_COLLECT, URL_CARDS_CATEGORIES, URL_CARDS_LIST, \ - MSG_CURRENT_BALANCE, URL_CARDS_UPGRADE, URL_LUCKY_BOUNTY, MSG_NO_CARDS_TO_UPGRADE, MSG_SORTING_CARDS, \ +from bots.tapcoins.config import BUY_UPGRADES, UPGRADES_COUNT +from bots.tapcoins.strings import HEADERS, URL_INIT, URL_LOGIN, URL_CARDS_CATEGORIES, URL_CARDS_LIST, \ + URL_CARDS_UPGRADE, URL_LUCKY_BOUNTY, MSG_NO_CARDS_TO_UPGRADE, \ MSG_CARD_UPGRADED, MSG_NOT_ENOUGH_COINS, MSG_CARD_UPGRADED_COMBO, URL_DAILY, URL_DAILY_COMPLETE, \ - MSG_LOGIN_BONUS_COMPLETE, URL_USER_INFO + MSG_LOGIN_BONUS_COMPLETE, URL_USER_INFO, MSG_UPGRADING_CARDS, MSG_UPGRADE_COMPLETE DEFAULT_EST_TIME = 60 * 45 @@ -40,69 +41,76 @@ def authenticate(self, *args, **kwargs): self.is_alive = False def set_start_time(self): - try: - cards = self.get_cards() - if not cards: - self.log(MSG_NO_CARDS_TO_UPGRADE) - return + if BUY_UPGRADES: + try: + cards = self.get_cards() + if not cards: + self.log(MSG_NO_CARDS_TO_UPGRADE) + return - self.log(MSG_SORTING_CARDS) + cards = sorted(cards, key=lambda x: x['upgrade_earnings'] / x['upgrade_cost'], reverse=True) - cards = sorted(cards, key=lambda x: x['upgrade_earnings'] / x['upgrade_cost'], reverse=True) + self.get_balance() + self.get_hour_earnings() - self.get_balance() - self.get_hour_earnings() - - earnings_per_second = round(self.hours_earnings / 3600) + earnings_per_second = round(self.hours_earnings / 3600) - first_card = cards[0] - time_to_upgrade = round(first_card['upgrade_cost'] / earnings_per_second) + random.randint(60, 120) + first_card = cards[0] + time_to_upgrade = round(first_card['upgrade_cost'] / earnings_per_second) + random.randint(60, 120) - self.start_time = time() + time_to_upgrade - except Exception as e: + self.start_time = time() + time_to_upgrade + except Exception as e: + est_time = DEFAULT_EST_TIME + self.start_time = time() + est_time + else: est_time = DEFAULT_EST_TIME self.start_time = time() + est_time - def get_balance(self): - data = { - 'coin': 0, - 'power': 1500, - 'turbo': 0, - '_token': self.token - } + def upgrade_cards(self): + if BUY_UPGRADES: + self.log(MSG_UPGRADING_CARDS) - response = self.post(URL_COLLECT, data=data) - json = response.json() - self.balance = json['data']['userInfo']['coin'] + upgrades_left = UPGRADES_COUNT - self.log(MSG_CURRENT_BALANCE.format(result=self.balance)) + while True: + cards = self.get_cards() + if not cards: + self.log(MSG_NO_CARDS_TO_UPGRADE) + break - def upgrade_cards(self): - while True: - cards = self.get_cards() - if not cards: - self.log(MSG_NO_CARDS_TO_UPGRADE) - break + cards = sorted(cards, key=lambda x: x['upgrade_earnings'] / x['upgrade_cost'], reverse=True) - self.log(MSG_SORTING_CARDS) + self.get_balance() - cards = sorted(cards, key=lambda x: x['upgrade_earnings'] / x['upgrade_cost'], reverse=True) + upgraded = False - self.get_balance() + for card in cards: + if upgrades_left == 0: + # Если upgrades_count равен 0, прокачиваем на весь баланс + while self.balance >= card['upgrade_cost']: + self.post(URL_CARDS_UPGRADE, {'taskId': card['id'], '_token': self.token}) + self.get_balance() # Обновляем баланс после каждой прокачки + self.log(MSG_CARD_UPGRADED.format(card['name'])) + upgraded = True + break - upgraded = False + if self.balance >= card['upgrade_cost']: + self.post(URL_CARDS_UPGRADE, {'taskId': card['id'], '_token': self.token}) + upgraded = True + upgrades_left -= 1 - for card in cards: - if self.balance >= card['upgrade_cost']: - self.post(URL_CARDS_UPGRADE, {'taskId': card['id'], '_token': self.token}) - upgraded = True + self.log(MSG_CARD_UPGRADED.format(card['name'])) + break - self.log(MSG_CARD_UPGRADED.format(card['name'])) + if not upgraded: + self.log(MSG_NOT_ENOUGH_COINS) break - if not upgraded: - self.log(MSG_NOT_ENOUGH_COINS) - break + if upgrades_left == 0: + self.log("Достигнуто максимальное количество прокачек") + break + + self.log(MSG_UPGRADE_COMPLETE) def get_cards(self): categories_response = self.post(URL_CARDS_CATEGORIES, data={'_token': self.token}) @@ -186,6 +194,13 @@ def get_hour_earnings(self): self.hours_earnings = data['hour_earnings'] + def get_balance(self): + + response = self.post(URL_USER_INFO, {'_token': self.token}) + data = response.json()['data'] + + self.balance = data['balance'] + def farm(self): self.get_balance() self.daily_bonus() diff --git a/bots/tapcoins/config.py b/bots/tapcoins/config.py new file mode 100644 index 0000000..b73106d --- /dev/null +++ b/bots/tapcoins/config.py @@ -0,0 +1,2 @@ +BUY_UPGRADES = True # Покупать ли апгрейды +UPGRADES_COUNT = 0 # Количество апгрейдов за раз, если 0 - то покупаем на весь баланс diff --git a/bots/tapcoins/strings.py b/bots/tapcoins/strings.py index 49be803..f2bb8d5 100644 --- a/bots/tapcoins/strings.py +++ b/bots/tapcoins/strings.py @@ -27,12 +27,10 @@ 'User-Agent': 'Mozilla/5.0 (Linux; Android 11; Redmi 5 Plus Build/RQ3A.210805.001.A1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.64 Mobile Safari/537.36' } -MSG_CURRENT_BALANCE = 'Текущий баланс: {result}' MSG_STARTING_UPDATING_CARDS = 'Начало прокачивания карточек' -MSG_UPDATING_CARDS = 'Прокачивание карточек' +MSG_UPGRADING_CARDS = 'Прокачивание карточек' MSG_UPGRADE_COMPLETE = 'Прокачка карточек завершена' MSG_NO_CARDS_TO_UPGRADE = "Не найдены карты для прокачки" -MSG_SORTING_CARDS = "Сортирую карточки по уровню дохода" MSG_CARD_UPGRADED = "Прокачана карта {}" MSG_NOT_ENOUGH_COINS = "Не хватает монет для прокачки" MSG_CARD_UPGRADED_COMBO = "Прокачана карта для комбо {}"