generate_domain.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2023/03/08 20:18:13
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : 批量生成域名(双拼,双单词,双单词拼接)
  8. 参考项目: https://git.yoqi.me/lyq/SearchDomain
  9. '''
  10. import csv,os
  11. class GenerateDomain(object):
  12. def __init__(self, params: dict,):
  13. '''初始化列表'''
  14. self.initPinYin=[]
  15. self.params = params
  16. self.keyword= self.params['keyword'].split(',')
  17. # self.yuming=["com","cn","me","net"]
  18. self.yuming = self.params["domain"].split(',')
  19. self.composePinYin=[]
  20. self.composeDomain=[]
  21. def run(self):
  22. """ 批量生成域名, 保存到 domain.txt """
  23. with open(os.path.join(self.params["app_path"], r"data/a.csv"), "r", encoding="utf-8") as f:
  24. csv_data = csv.reader(f)
  25. for row in csv_data:
  26. for pinyin in row:
  27. if(pinyin != ""):
  28. self.initPinYin.append(pinyin)
  29. for i in self.initPinYin:
  30. for j in self.keyword:
  31. if self.params["position"]=="prefix":
  32. self.composePinYin.append(i+j)
  33. else:
  34. self.composePinYin.append(j+i)
  35. for i in self.composePinYin:
  36. for j in self.yuming:
  37. self.composeDomain.append(i+"."+j)
  38. with open(os.path.join(self.params["app_path"], "domain.txt"),"w",encoding="utf-8") as file:
  39. for i in self.composeDomain:
  40. file.write(i+"\n")