-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
93 lines (75 loc) · 2.78 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
@ Author: Mr.Hat
@ Date: 2024/3/30 14:05
@ Description:
@ History:
"""
import asyncio
import random
import sys
import traceback
import aiohttp
from core import Grass
from core.autoreger import AutoReger
from core.utils import logger
from core.utils.exception import LowProxyScoreException, ProxyScoreNotFoundException, ProxyForbiddenException
from core.utils.generate.person import Person
from data.config import ACCOUNTS_FILE_PATH, PROXIES_FILE_PATH, REGISTER_ACCOUNT_ONLY, THREADS
async def worker_task(_id, account: str, proxy: str = None):
consumables = account.split(":")[:2]
if len(consumables) == 1:
email = consumables[0]
password = Person().random_string(8)
else:
email, password = consumables
grass = None
sleep_time = 20
await asyncio.sleep(random.uniform(1, 1.5) * _id)
logger.info(f"Starting №{_id} | {email} | {password} | {proxy}")
for _ in range(1000):
try:
grass = Grass(_id, email, password, proxy)
if REGISTER_ACCOUNT_ONLY:
await grass.create_account()
else:
await grass.start()
return True
except ProxyForbiddenException as e:
logger.info(f"{_id} | {e}")
break
except ProxyScoreNotFoundException as e:
logger.info(f"Waiting {sleep_time} minutes. {e}")
await asyncio.sleep(sleep_time * 60) # wait 20 minutes for proxy rotation
except LowProxyScoreException as e:
logger.info(f"Waiting {sleep_time} minutes. {e}")
await asyncio.sleep(sleep_time * 60) # wait 20 minutes for proxy rotation
except aiohttp.ClientError as e:
log_msg = str(e) if "</html>" not in str(e) else "Html page response, 504"
logger.error(f"{_id} | Server not responding | Error: {log_msg}")
await asyncio.sleep(5)
except Exception as e:
logger.error(f"{_id} | not handled exception | error: {e} {traceback.format_exc()}")
finally:
if grass:
await grass.session.close()
async def main():
autoreger = AutoReger.get_accounts(
ACCOUNTS_FILE_PATH, PROXIES_FILE_PATH,
with_id=True
)
if REGISTER_ACCOUNT_ONLY:
msg = "Register account only mode!"
threads = THREADS
else:
msg = "Mining mode ON"
threads = len(autoreger.accounts)
logger.info(f"Threads: {threads} | {msg} ")
await autoreger.start(worker_task, threads)
if __name__ == "__main__":
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())
else:
asyncio.run(main())