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