main.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import aiohttp
  2. import asyncio
  3. import re
  4. import random
  5. class GrassRest:
  6. def __init__(self, email: str, password: str, user_agent: str = None, proxy: str = None):
  7. self.email = email
  8. self.password = password
  9. self.user_agent = user_agent
  10. self.proxy = proxy
  11. self.website_headers = {
  12. 'authority': 'api.getgrass.io',
  13. 'accept': 'application/json, text/plain, */*',
  14. 'accept-language': 'uk-UA,uk;q=0.9,en-US;q=0.8,en;q=0.7',
  15. 'content-type': 'application/json',
  16. 'origin': 'https://app.getgrass.io',
  17. 'referer': 'https://app.getgrass.io/',
  18. 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
  19. 'sec-ch-ua-mobile': '?0',
  20. 'sec-ch-ua-platform': '"Windows"',
  21. 'sec-fetch-dest': 'empty',
  22. 'sec-fetch-mode': 'cors',
  23. 'sec-fetch-site': 'same-site',
  24. 'user-agent': self.user_agent,
  25. }
  26. self.session = None
  27. async def login(self):
  28. url = 'https://api.getgrass.io/login'
  29. json_data = {
  30. 'password': self.password,
  31. 'username': self.email,
  32. }
  33. async with self.session.post(url, headers=self.website_headers, json=json_data, proxy=self.proxy) as response:
  34. if response.status != 200:
  35. raise Exception(f"Login failed for {self.email}: {await response.text()}")
  36. return await response.json()
  37. async def enter_account(self):
  38. res_json = await self.login()
  39. self.website_headers['Authorization'] = res_json['result']['data']['accessToken']
  40. return res_json['result']['data']['userId']
  41. async def main():
  42. # 账号列表
  43. account_list = [
  44. # 'jack0210_@hotmail.com',
  45. 'yujiec0210@gmail.com',
  46. 'yujieccyj01@hotmail.com',
  47. 'yujieccyj02@hotmail.com',
  48. 'yujieccyj03@hotmail.com',
  49. 'yujieccyj04@hotmail.com',
  50. 'yujieccyj05@hotmail.com',
  51. 'yujieccyj06@hotmail.com',
  52. 'yujieccyj07@hotmail.com',
  53. 'yujieccyj08@hotmail.com',
  54. 'yujieccyj09@hotmail.com',
  55. 'yujieccyj10@hotmail.com',
  56. 'yujieccyj11@hotmail.com'
  57. ]
  58. # 密码(假设所有账号的密码相同,如果不同请自行修改)
  59. password = "aaaAAA111!!!"
  60. user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
  61. proxy = None # 如果需要代理,可以设置代理地址
  62. async with aiohttp.ClientSession() as session:
  63. tasks = []
  64. for email in account_list:
  65. grass_rest = GrassRest(email, password, user_agent, proxy)
  66. grass_rest.session = session
  67. tasks.append(grass_rest.enter_account())
  68. user_ids = await asyncio.gather(*tasks, return_exceptions=True)
  69. with open("account.txt", "w") as f:
  70. for email, user_id in zip(account_list, user_ids):
  71. if isinstance(user_id, Exception):
  72. print(f"{email}: Error - {user_id}")
  73. else:
  74. print(f"{email}: {user_id}")
  75. f.write(f"{user_id}\n")
  76. print("UserID 获取完成,已保存到 account.txt 文件中。")
  77. def add_proxy():
  78. with open("account.txt", "r") as f:
  79. user_ids = f.readlines()
  80. str_data = ''
  81. for index, user_id in enumerate(user_ids, start=1):
  82. user_id_and_proxy = f"{user_id.strip()}==socks5://47.79.34.67:600{str(index).zfill(2)}"
  83. str_data += user_id_and_proxy + '\n'
  84. with open("account_proxy.txt", "w") as f:
  85. f.write(str_data)
  86. if __name__ == "__main__":
  87. asyncio.run(main())
  88. # 顺手添加代理
  89. add_proxy()