generate_email.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2023/03/26 15:40:11
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : generate email and password
  8. '''
  9. import random
  10. import argparse
  11. argparser = argparse.ArgumentParser()
  12. argparser.add_argument("-n", "--number", help="number of email to generate, default is 5", default="5")
  13. argparser.add_argument("-sfx", "--suffix", help="email suffix, default is @outlook.com", default="@outlook.com")
  14. args = argparser.parse_args()
  15. initList = []
  16. compose_account = []
  17. def generate_email(number: int, suffix: str) -> None:
  18. with open(("data/b.csv"), "r", encoding="utf-8") as f:
  19. csv_data = f.readlines()
  20. for row in csv_data:
  21. initList.append(row.strip())
  22. index = 1
  23. # random choose 3 from initList, and join them
  24. while index <= number:
  25. name = "".join(random.sample(initList, 2))
  26. account = name + str(random.randint(100, 999))
  27. password = ''.join(random.sample(
  28. 'abcdefghijklmnopqrstuvwxyz0123456789_', 12))
  29. compose_account.append({"email": account+suffix, "password": password})
  30. index += 1
  31. return compose_account
  32. def write_to_file():
  33. with open("res.txt", "a+", encoding="utf-8") as file:
  34. for i in compose_account:
  35. file.write(i["email"] + " " + i["password"]+"\n")
  36. def main():
  37. generate_email(number,suffix=args.suffix)
  38. write_to_file()
  39. if __name__ == '__main__':
  40. if args.number:
  41. if args.number.isdigit() and int(args.number) > 0 and int(args.number) < 1000:
  42. number = int(args.number)
  43. else:
  44. print("please input a number between 1 and 1000")
  45. exit(1)
  46. main()