email_log.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # coding=utf-8
  2. # + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +
  3. # ┏┓   ┏┓+ +
  4. #    ┏┛┻━━━┛┻┓ + +
  5. #    ┃       ┃  
  6. #    ┃   ━   ┃ ++ + + +
  7. #    ████━████ ┃+
  8. #    ┃       ┃ +
  9. #    ┃   ┻   ┃
  10. #    ┃       ┃ + +
  11. #    ┗━┓   ┏━┛
  12. #      ┃   ┃           
  13. #      ┃   ┃ + + + +
  14. #      ┃   ┃    Codes are far away from bugs with the animal protecting   
  15. #      ┃   ┃ +     神兽保佑,代码无bug  
  16. #      ┃   ┃
  17. #      ┃   ┃  +         
  18. #      ┃    ┗━━━┓ + +
  19. #      ┃        ┣┓
  20. #      ┃        ┏┛
  21. #      ┗┓┓┏━┳┓┏┛ + + + +
  22. #       ┃┫┫ ┃┫┫
  23. #       ┗┻┛ ┗┻┛+ + + +
  24. # + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +"""
  25. """
  26. """
  27. import base64
  28. import hashlib
  29. import time
  30. import datetime
  31. def getTimeDict(times):
  32. time_dict = []
  33. t = 0
  34. for x in range(24):
  35. if x < 10:
  36. x = '0' + str(x)
  37. else:
  38. x = str(x)
  39. # a = times.strftime("%Y-%m-%d") + " " + x
  40. a = times.strftime("%Y%m%d") + x
  41. time_dict.append(a)
  42. t += 1
  43. return time_dict
  44. def md5s(text, isBackByte=False):
  45. """md5加密函数"""
  46. md5 = hashlib.md5()
  47. if isinstance(text, bytes):
  48. md5.update(text)
  49. else:
  50. md5.update(text.encode('utf-8'))
  51. if isBackByte:
  52. # 返回二进制的加密结果
  53. return md5.digest()
  54. # 返回十六进制的机密结果
  55. return md5.hexdigest()
  56. def base64_encode(text, isBytes=False):
  57. """进行base64编码处理"""
  58. if isBytes:
  59. return base64.b64encode(text)
  60. return base64.b64encode(bytes(text, encoding="utf-8"))
  61. def get_timestamp10():
  62. """获取当前时间长度为10位长度的时间戳"""
  63. return int(time.time())
  64. def get_sign_url_content(to_tt):
  65. # url = '13.56.141.156:81'
  66. # url = '35.176.238.187:81'
  67. url = '111.230.145.16:81'
  68. secret = 'ansjer'; # 密钥--对应#st的哈希格式为 secret+url+e,e为时间戳单位s,url为请求地址 secure_link_md5 xiaozhong.com$uri$arg_e;
  69. # path = '/hls/5553.mp4/index.m3u8' # 下载文件
  70. # path = '/L59KVYDAEPHR1T6M111A_0/555666.mp4' # 下载文件
  71. path = '/Relay' + to_tt + '.txt' # 下载文件
  72. # path = '/444.mp4' # 下载文件
  73. # 下载到期时间,time是当前时间,300表示300秒,也就是说从现在到300秒之内文件不过期
  74. expire = get_timestamp10() + 3600;
  75. res = md5s(str(secret) + str(path) + str(expire), True)
  76. md5_str = str(base64_encode(res, True))
  77. md5_str = md5_str.replace('b\'', '').replace('\'', '').replace('+', '-').replace('/', '_').replace('=', '')
  78. sig_uri = 'http://' + url + path + '?' + 'st=' + str(md5_str) + '&e=' + str(expire)
  79. # print(sig_uri)
  80. return {
  81. 'url' : sig_uri,
  82. 'time' :to_tt
  83. }
  84. to_date = datetime.datetime.now() - datetime.timedelta(days=1)
  85. to_list = getTimeDict(to_date)
  86. HTML_DATA = ''
  87. # sign_uri_list = []
  88. for tt in to_list:
  89. su = get_sign_url_content(to_tt=tt)
  90. HTML_DATA +='<p><span><a href="{{url}}" target="_Blank">{{time}}<a></span></p>'.replace("{{time}}",su['time']).replace("{{url}}",su['url'])
  91. # sign_uri_list.append(su)
  92. # print(sign_uri_list)
  93. # print(HTML_DATA)
  94. print(type(HTML_DATA))
  95. from boto3.session import Session
  96. import traceback
  97. AWS_ACCESS_ID = 'AKIAJKPU23EU5QWHFPKQ'
  98. AWS_ACCESS_SECRET = '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'
  99. AWS_ACCESS_REGION = 'us-east-1'
  100. COMPANY_EMAIL = 'user_server@nsst.com'
  101. session = Session(
  102. aws_access_key_id=AWS_ACCESS_ID,
  103. aws_secret_access_key=AWS_ACCESS_SECRET,
  104. region_name=AWS_ACCESS_REGION,
  105. )
  106. conn = session.client('ses')
  107. try:
  108. response = conn.send_email(
  109. # 发送人
  110. Source=COMPANY_EMAIL,
  111. Destination={
  112. # 收件人
  113. 'ToAddresses': [COMPANY_EMAIL]
  114. # 'ToAddresses': ['1758730877@qq.com']
  115. },
  116. Message={
  117. # 标题
  118. 'Subject': {
  119. # 'Data': '英国P2P日志文件',
  120. 'Data': '中国P2P日志文件',
  121. # 'Data': '美国P2P日志文件',
  122. 'Charset': 'utf-8'
  123. },
  124. 'Body': {
  125. 'Html': {
  126. 'Charset': 'UTF-8',
  127. 'Data': HTML_DATA,
  128. },
  129. }
  130. },
  131. )
  132. except Exception as e:
  133. errorInfo = traceback.format_exc()
  134. print(errorInfo)
  135. else:
  136. print('yes')