Explorar o código

open weather调用次数设置邮件提醒

locky hai 1 ano
pai
achega
d066291a5e
Modificáronse 1 ficheiros con 14 adicións e 1 borrados
  1. 14 1
      Object/IPWeatherObject.py

+ 14 - 1
Object/IPWeatherObject.py

@@ -7,9 +7,10 @@ import geoip2.webservice
 import requests
 
 from Model.models import IPAddr, OpenWeatherMapCallCount
+from Object.AWS.S3Email import S3Email
 from Object.RedisObject import RedisObject
 from Service.CommonService import CommonService
-from Ansjer.config import LOGGER
+from Ansjer.config import LOGGER, CONFIG_INFO
 
 
 class IPQuery:
@@ -211,6 +212,18 @@ class OpenWeatherMap:
         else:
             count = open_weather_map_call_count_qs[0]['count'] + 1
             open_weather_map_call_count_qs.update(count=count)
+            # 调用次数超过750,000,邮件提醒
+            warning_count = 750000
+            if count > warning_count:
+                redis_obj = RedisObject()
+                key = 'open_weather_map_call_count_warning_time_limit'
+                time_limit = redis_obj.get_data(key)
+                if not time_limit:
+                    # 限制一天提醒一次
+                    redis_obj.set_data(key, 1, 60 * 60 * 24)
+                    subject = '邮件提醒'
+                    data = '{}服open weather调用次数大于{}'.format(CONFIG_INFO, warning_count)
+                    S3Email().send_email(subject, data, 'servers@ansjer.com')
 
         if res.status_code != 200:
             return None, None