-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
82 lines (64 loc) · 2.35 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
import asyncio
import platform
import random
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
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(e)
break
except LowProxyScoreException as e:
logger.info(e)
break
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 platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())