main.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from MyUtils.HttpRequestsUtil import HttpRequestsUtil
  2. import schedule
  3. import datetime,time
  4. import pytz
  5. from MyUtils.MysqlUtils import MysqlUtils
  6. INSERT_SQL = "insert into aircondition_open_rate(project_id,create_time,`value`) values "
  7. def datetime_now():
  8. # datetime_now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  9. #容器时间
  10. # tz = pytz.timezone('Asia/Shanghai') # 东八区
  11. datetime_now = datetime.datetime.fromtimestamp(int(time.time()),
  12. pytz.timezone('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S')
  13. return datetime_now
  14. url = "http://web.sagacloud.cn:8008/sgdaping/duoduo-service/setup-service/environment/queryConditionerStatus?projectId="
  15. projectId = "Pj1101020002"
  16. mysql = {'database': 'sagacloud_customization', 'host': 'rm-2zek656j2bn934176xo.mysql.rds.aliyuncs.com', 'passwd': 'H%k3!BHw1kQXIc70', 'port': 53306, 'user': 'root'}
  17. def job():
  18. httputil = HttpRequestsUtil()
  19. data = httputil.get(url,projectId)["data"]["openRate"]
  20. # #连接hbase
  21. MysqlUtil = MysqlUtils(**mysql)
  22. sql ="('%s','%s','%s')"%(projectId,datetime_now(),data)
  23. insert_sql = INSERT_SQL+sql
  24. MysqlUtil.update(insert_sql)
  25. MysqlUtil.close()
  26. print(datetime_now(),data)
  27. # 每小时的第0分钟执行job函数
  28. schedule.every().hour.at(":00").do(job)
  29. while True:
  30. schedule.run_pending()
  31. time.sleep(61)