domain_notify.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import whois
  2. from concurrent.futures import ThreadPoolExecutor
  3. import os,sys,re,json
  4. # import requests
  5. import time
  6. from .push import EmailPush
  7. class DomainNotify(object):
  8. """域名到期推送"""
  9. def __init__(self):
  10. super(DomainNotify,self).__init__()
  11. def crawl(self, domain:str)->None:
  12. '''
  13. 检测域名是否快到期,推送邮件
  14. :params domain 域名:
  15. :return true or false'''
  16. try:
  17. whi = whois.whois(domain)
  18. expirationDate= whi.expiration_date
  19. notifyDate = str(expirationDate - time.datetime.timedelta(days=1))
  20. today=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  21. days=DomainNotify.getDays(notifyDate,today)
  22. if days <=3:
  23. push=EmailPush()
  24. push.push()
  25. except Exception as e:
  26. print(e)
  27. self.notify(domain)
  28. @staticmethod
  29. def getDays(notifyDay:str, today:str):
  30. pass
  31. def notify(self,domain):
  32. '''结果推送'''
  33. pass
  34. def saveRes(damin:str, res:bool):
  35. # mysql.save()
  36. # file.save()
  37. pass
  38. def run(self):
  39. with open("res/res.json","w",encoding="utf8") as file:
  40. pool=ThreadPoolExecutor(max_workers=10)
  41. for i in range(100):
  42. pool.submit(self.crawl, domain)
  43. if __name__ == '__main__':
  44. sd = DomainNotify()
  45. sd.run()