39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from cm_bot_hal import CM_BOT_HAL
|
|
import logging, time, requests, json
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
from datetime import datetime
|
|
import os
|
|
|
|
# Suppress httpx logs
|
|
logging.getLogger("httpx").setLevel(logging.WARNING)
|
|
|
|
# api_url = 'https://api.luckytown888.net'
|
|
api_url = 'http://api-server:3000'
|
|
max_threading = 1
|
|
|
|
def transfer(data: dict, local_logger):
|
|
bot = CM_BOT_HAL()
|
|
local_logger.info(f"[Start] Transfer Credit from {data['f_username']} to {data['t_username']}")
|
|
bot.transfer_credit_api(data['f_username'], data['f_password'], data['t_username'], data['t_password'])
|
|
local_logger.info(f"[Done] {data['f_username']} transfer done!")
|
|
del bot
|
|
time.sleep(0.5)
|
|
|
|
while True:
|
|
weekday = int(datetime.now().strftime("%w"))
|
|
hour = int(datetime.now().strftime("%H"))
|
|
minutes = int(datetime.now().strftime("%M"))
|
|
if weekday == 1 and (hour >= 6 and hour < 13):
|
|
local_logger = logging.getLogger(f"{__name__}")
|
|
response = requests.get(f'{api_url}/user')
|
|
items = json.loads(response.text)
|
|
total_items = len(items) if isinstance(items, list) else 0
|
|
if total_items == 0:
|
|
local_logger.info("No items to process.")
|
|
else:
|
|
local_logger.info(f"Processing {total_items} transfer items...")
|
|
with ThreadPoolExecutor(max_workers=max_threading) as executor:
|
|
results = list(executor.map(lambda item: transfer(item, local_logger), items))
|
|
local_logger.info(f"Completed processing {total_items} transfer items.")
|
|
time.sleep(1)
|