http://ip-api.com/json
import time
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
import datetime
now_time = datetime.datetime.now().strftime('%Y-%m-%d')
print(now_time)
import datetime
import decimal
import math
def handle_data():
end_date = datetime.datetime.now()
start_date = datetime.datetime.strptime('1989-12-09', '%Y-%m-%d')
e_y = end_date.year
e_m = end_date.month
e_d = end_date.day
s_y = start_date.year
s_m = start_date.month
s_d = start_date.day
diff_y = e_y - s_y
diff_m = e_m - s_m
diff_d = e_d - s_d
diff_info = diff_y * 12 + diff_m + (decimal.Decimal(str(diff_d)) / decimal.Decimal('31'))
print('相差月份数: %s' %(diff_info))
info = divmod(diff_info, 12)
y_cnt = int(info[0])
m_cnt = int(math.modf(info[1])[1])
d_cnt = (decimal.Decimal(str(math.modf(info[1])[0])) * decimal.Decimal('31')).quantize(decimal.Decimal('0'))
print ('相差:%s年%s月%s天' %(y_cnt, m_cnt, d_cnt))
if __name__ == '__main__':
handle_data()
import hashlib
str = '123456'
str_md5 = hashlib.md5(str.encode(encoding='utf-8')).hexdigest()
print(str_md5)
def generate_phone():
"""
random phone
:return:
"""
phone = ''
phone += ''.join(random.sample(string.digits, 7))
return phone
一些加密方法
import base64
import hmac
from hashlib import sha256
def get_apikey(key1, key2):
"""获取header x_api_key"""
key1 = key1.encode('utf-8')
key2 = key2.encode('utf-8')
api_key = base64.b64encode(hmac.new(key2, key1, digestmod=sha256).digest())
api_key = str(api_key, 'utf-8')
return api_key