__init__.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2025/09/30 22:31:02
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : alidriver_checkin script main entry
  8. '''
  9. import os
  10. import argparse
  11. from .crawl_lycheeshare import LycheeShare, DATA_DIR
  12. def main():
  13. parser = argparse.ArgumentParser(description='LycheeShare 自动化工具')
  14. parser.add_argument('command', choices=['generate', 'register', 'checkin', 'token', 'credit'],
  15. help='命令: generate(生成账户), register(批量注册), checkin(批量签到), token(批量获取token), credit(查询额度)')
  16. parser.add_argument('-n', '--number', type=int, default=1, help='生成账户数量 (用于generate命令)')
  17. args = parser.parse_args()
  18. if args.command == 'generate':
  19. lychee = LycheeShare('', '')
  20. lychee.generate_account(args.number)
  21. print(f"已生成 {args.number} 个账户到 {os.path.join(DATA_DIR, 'generate_account.txt')}")
  22. elif args.command == 'register':
  23. # 读取 generate_account.txt 批量注册
  24. generate_file = os.path.join(DATA_DIR, 'generate_account.txt')
  25. if not os.path.exists(generate_file):
  26. print(f"错误: 未找到 {generate_file} 文件,请先运行 generate 命令")
  27. return
  28. with open(generate_file, 'r') as f:
  29. lines = f.readlines()
  30. print(f"开始批量注册,共 {len(lines)} 个账户")
  31. success_count = 0
  32. for line in lines:
  33. parts = line.strip().split(',')
  34. if len(parts) < 3:
  35. print(f"跳过格式错误的行: {line.strip()}")
  36. continue
  37. username, email, password = parts[0], parts[1], parts[2]
  38. print(f"\n正在注册: {username} ({email})")
  39. lychee = LycheeShare(email, password)
  40. # 发送验证码(自动返回000000)
  41. success, result = lychee.get_captcha()
  42. if not success:
  43. print(f"发送验证码失败,跳过: {email}")
  44. continue
  45. # 自动使用验证码000000
  46. code = "000000"
  47. print(f"使用验证码: {code}")
  48. # 注册
  49. success, result = lychee.register(username, code)
  50. if success:
  51. # 注册成功,保存到 account.txt
  52. account_file = os.path.join(DATA_DIR, 'account.txt')
  53. with open(account_file, 'a') as af:
  54. af.write(f"{username},{email},{password}\n")
  55. success_count += 1
  56. print(f"注册成功并保存到 {account_file}: {email}")
  57. # 添加延迟避免频繁请求
  58. import time
  59. import random
  60. time.sleep(10*60*random.random()) # 随机延迟1到10分钟
  61. print(f"\n批量注册完成!成功 {success_count}/{len(lines)} 个账户")
  62. elif args.command == 'checkin':
  63. # 读取 account.txt 批量签到
  64. account_file = os.path.join(DATA_DIR, 'account.txt')
  65. if not os.path.exists(account_file):
  66. print(f"错误: 未找到 {account_file} 文件,请先运行 register 命令")
  67. return
  68. with open(account_file, 'r') as f:
  69. lines = f.readlines()
  70. print(f"开始批量签到,共 {len(lines)} 个账户")
  71. success_count = 0
  72. for line in lines:
  73. parts = line.strip().split(',')
  74. if len(parts) < 3:
  75. print(f"跳过格式错误的行: {line.strip()}")
  76. continue
  77. username, email, password = parts[0], parts[1], parts[2]
  78. print(f"\n正在签到: {username} ({email})")
  79. lychee = LycheeShare(email, password)
  80. # 尝试加载cookie
  81. if lychee.load_cookies():
  82. print("使用已保存的登录状态")
  83. else:
  84. print("未找到登录状态,正在登录...")
  85. success, _ = lychee.login()
  86. if not success:
  87. print(f"登录失败,跳过: {email}")
  88. continue
  89. # 签到
  90. success, _ = lychee.checkin()
  91. if success:
  92. success_count += 1
  93. # 添加延迟避免频繁请求
  94. import time
  95. time.sleep(1)
  96. print(f"\n批量签到完成!成功 {success_count}/{len(lines)} 个账户")
  97. elif args.command == 'token':
  98. # 读取 account.txt 批量获取token
  99. account_file = os.path.join(DATA_DIR, 'account.txt')
  100. if not os.path.exists(account_file):
  101. print(f"错误: 未找到 {account_file} 文件,请先运行 register 命令")
  102. return
  103. with open(account_file, 'r') as f:
  104. lines = f.readlines()
  105. print(f"开始批量获取token,共 {len(lines)} 个账户")
  106. success_count = 0
  107. # 清空原有的 api_tokens.txt
  108. token_file = os.path.join(DATA_DIR, 'api_tokens.txt')
  109. if os.path.exists(token_file):
  110. os.remove(token_file)
  111. for line in lines:
  112. parts = line.strip().split(',')
  113. if len(parts) < 3:
  114. print(f"跳过格式错误的行: {line.strip()}")
  115. continue
  116. username, email, password = parts[0], parts[1], parts[2]
  117. print(f"\n正在获取token: {username} ({email})")
  118. lychee = LycheeShare(email, password)
  119. # 尝试加载cookie
  120. if lychee.load_cookies():
  121. print("使用已保存的登录状态")
  122. else:
  123. print("未找到登录状态,正在登录...")
  124. success, _ = lychee.login()
  125. if not success:
  126. print(f"登录失败,跳过: {email}")
  127. continue
  128. # 获取token
  129. success, _ = lychee.get_token()
  130. if success:
  131. success_count += 1
  132. # 添加延迟避免频繁请求
  133. import time
  134. time.sleep(1)
  135. print(f"\n批量获取token完成!成功 {success_count}/{len(lines)} 个账户")
  136. print(f"所有token已保存到 {os.path.join(DATA_DIR, 'api_tokens.txt')}")
  137. elif args.command == 'credit':
  138. # 读取 account.txt 批量查询额度
  139. account_file = os.path.join(DATA_DIR, 'account.txt')
  140. if not os.path.exists(account_file):
  141. print(f"错误: 未找到 {account_file} 文件,请先运行 register 命令")
  142. return
  143. with open(account_file, 'r') as f:
  144. lines = f.readlines()
  145. print(f"开始批量查询额度,共 {len(lines)} 个账户")
  146. success_count = 0
  147. # 清空原有的 credits.txt
  148. credit_file = os.path.join(DATA_DIR, 'credits.txt')
  149. if os.path.exists(credit_file):
  150. os.remove(credit_file)
  151. for line in lines:
  152. parts = line.strip().split(',')
  153. if len(parts) < 3:
  154. print(f"跳过格式错误的行: {line.strip()}")
  155. continue
  156. username, email, password = parts[0], parts[1], parts[2]
  157. print(f"\n正在查询额度: {username} ({email})")
  158. lychee = LycheeShare(email, password)
  159. # 尝试加载cookie
  160. if lychee.load_cookies():
  161. print("使用已保存的登录状态")
  162. else:
  163. print("未找到登录状态,正在登录...")
  164. success, _ = lychee.login()
  165. if not success:
  166. print(f"登录失败,跳过: {email}")
  167. continue
  168. # 查询额度
  169. success, _ = lychee.get_credit()
  170. if success:
  171. success_count += 1
  172. # 添加延迟避免频繁请求
  173. import time
  174. time.sleep(1)
  175. print(f"\n批量查询额度完成!成功 {success_count}/{len(lines)} 个账户")
  176. print(f"所有额度信息已保存到 {os.path.join(DATA_DIR, 'credits.txt')}")
  177. if __name__ == '__main__':
  178. main()