forked from jimlee2048/Actions-WoZaiXiaoYuanPuncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
39 lines (32 loc) · 1.05 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
import datetime
import time
import pytz
import random
# 获取当前时间(云函数的运行环境是 0 时区时间,需要 +8 转化为北京时间)
def getCurrentTime():
return datetime.datetime.now(pytz.timezone('Asia/Shanghai')).strftime("%Y-%m-%d %H:%M:%S")
# 获取当前小时
def getCurrentHour():
return datetime.datetime.now(pytz.timezone('Asia/Shanghai')).hour
# 获取随机温度
def getRandomTemperature(self,temperature='36.0~36.5'):
if temperature.find('~') == -1:
return str(float(temperature))
else:
scope = temperature.split('~')
random.seed(time.ctime())
return "{:.1f}".format(random.uniform(float(scope[0]),float(scope[1])))
# 读写 json 文件
class processJson:
def __init__(self,path):
self.path = path
def read(self):
with open(self.path,'rb') as file:
data = json.load(file)
file.close()
return data
def write(self,data):
with open(self.path,'w',encoding='utf-8') as file:
json.dump(data,file,ensure_ascii = False,indent = 2)
file.close()