main.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. from httpx import AsyncClient
  2. from re import findall
  3. from os.path import exists
  4. from random import choice
  5. from loguru import logger
  6. import asyncio
  7. def get_proxy():
  8. return choice(proxies)
  9. async def _get_inbox_message(hash: str, eml: str):
  10. proxy = get_proxy()
  11. async with AsyncClient(proxies={
  12. "http://": proxy,
  13. "https://": proxy
  14. }) as client:
  15. url = ("https://api.mytemp.email/1/eml/get"
  16. f"?eml={eml}&hash={hash}&sid=9400042&task=163&tt=11209")
  17. response = await client.get(url)
  18. data = response.json()
  19. return findall(r"\d+", data["body_text"])[0]
  20. async def get_message(email: str, hash: str):
  21. proxy = get_proxy()
  22. async with AsyncClient(proxies={
  23. "http://": proxy,
  24. "https://": proxy
  25. }) as client:
  26. url = ("https://api.mytemp.email/1/inbox/check"
  27. f"?inbox={email}&hash={hash}&sid=9400042&task=7&tt=36")
  28. response = await client.get(url)
  29. data = response.json()
  30. for message in data["emls"]:
  31. if message["from_address"] == "noreply@m.step.app":
  32. return await _get_inbox_message(message["hash"], message["eml"])
  33. await asyncio.sleep(1)
  34. return await get_message(email, hash)
  35. async def get_email():
  36. proxy = get_proxy()
  37. async with AsyncClient(proxies={
  38. "http://": proxy,
  39. "https://": proxy
  40. }) as client:
  41. response = await client.post(
  42. "https://api.mytemp.email/1/inbox/create"
  43. "?sid=9400042"
  44. "&task=6&tt=35", json={
  45. "sid": 9400042,
  46. "task": 6,
  47. "tt": 35
  48. })
  49. data = response.json()
  50. try:
  51. return data["inbox"], data["hash"]
  52. except KeyError:
  53. await asyncio.sleep(1)
  54. return await get_email()
  55. async def register_account(r: str):
  56. logger.info("Регистрация акаунта")
  57. email, hash = await get_email()
  58. proxy = get_proxy()
  59. async with AsyncClient(cookies={"r": r}, proxies={
  60. "http://": proxy,
  61. "https://": proxy
  62. }) as client:
  63. response = await client.get("https://api.step.app/v1/auth/otp-code"
  64. f"?email={email}")
  65. data = response.text
  66. if "OK" not in data:
  67. raise Exception("Не удалось зарегистрировать аккаунт")
  68. code = await get_message(email, hash)
  69. response = await client.get("https://api.step.app/v1/auth/token"
  70. f"?email={email}"
  71. f"&code={code}")
  72. data = response.json()
  73. if "access" not in data:
  74. raise Exception("Не удалось зарегистрировать аккаунт")
  75. return email, data["access"]["token"], data["refresh"]["token"]
  76. async def add_referrer(r: str, access_token: str):
  77. logger.info("Установка реферального кода")
  78. proxy = get_proxy()
  79. async with AsyncClient(
  80. headers={"Authorization": f"Bearer {access_token}"},
  81. proxies={
  82. "http://": proxy,
  83. "https://": proxy
  84. }) as client:
  85. response = await client.patch(
  86. url="https://api.step.app/v1/user/me",
  87. json={"referrer": r})
  88. return "OK" in response.text
  89. async def worker(r: str):
  90. while True:
  91. logger.info("Попытка создать новый аккаунт")
  92. try:
  93. email, access_token, refresh_token = await register_account(r)
  94. if await add_referrer(r, access_token):
  95. logger.info("{} - Аккаунт успешно зарегистрирован", email)
  96. else:
  97. logger.info("{} - Не удалось установить реферальный код", email)
  98. await asyncio.sleep(1)
  99. except Exception:
  100. logger.exception("Ошибка при регистрации")
  101. async def main():
  102. referrer = input("Реф код - ")
  103. tasks = [asyncio.create_task(worker(referrer))
  104. for _ in range(int(input("Кол-во потоков - ")))]
  105. await asyncio.gather(*tasks)
  106. if exists("proxy.txt"):
  107. proxies = open("proxy.txt").read().strip().split("\n")
  108. else:
  109. proxies = [None]
  110. loop = asyncio.new_event_loop()
  111. asyncio.set_event_loop(loop)
  112. loop.run_until_complete(main())