Python脚本处理时间

-- coding: utf-8 --

import time, datetime
import requests
import hashlib
import json
import csv
url = ‘xxx’

def get_time_stamp13(datetime_obj, last_3digits_not_zero=0):
# 生成最后三位3位,微秒
data_microsecond = ‘000’
if last_3digits_not_zero == 1:
data_microsecond = str("%06d" % datetime_obj.microsecond)[0:3]

datetime_str = datetime.datetime.strftime(datetime_obj, '%Y-%m-%d %H:%M:%S')
datetime_obj = datetime.datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S')

date_stamp = str(int(time.mktime(datetime_obj.timetuple())))
date_stamp = date_stamp + data_microsecond
return int(date_stamp)

API_Secret = ‘aaaaaaaaaaaaaaaaaaaaaaaaaaa’
timestamp = str(get_time_stamp13(datetime.datetime.now(), last_3digits_not_zero=1))
nonce = ‘1111’
print(’[API_Secret]: %s\n[nonce]: %s\n[timestamp]: %s\n’ %(API_Secret, nonce, timestamp))
data_cyper = {
‘API_Secret’: API_Secret,
‘timestamp’: ‘’,
‘nonce’: ‘1111’,
}
data_cyper[‘timestamp’] = timestamp
print(’[signature字典]:’,data_cyper,end=’\n\n’)
#字典排序
data2 = sorted(data_cyper.values())
print(’[排序]:’,data2,end=’\n\n’)
passwd = ‘’
for i in data2:
passwd += i
print(’[拼接值]:’,passwd,end=’\n\n’)
x=hashlib.sha256()
x.update(passwd.encode(‘utf-8’))
enpasswd = x.hexdigest()
print(’[SHA256]:’,enpasswd,end=’\n\n’)
data={
‘username’: ‘xxx’,
‘signature’: ‘’,
‘timestamp’: ‘’,
‘nonce’: ‘1111’,
}
data[‘signature’] = enpasswd
data[‘timestamp’] = timestamp

for key,value in data.items():

# print(key,value)

resl= requests.post(url = url, data=data)

time_24h_before=str(int(timestamp)-86400000)
print(‘24小时前时间戳:’,time_24h_before)

#资产总数
url_ass_total = ‘xxx’
auth_token=‘Bearer ‘+resl.text[1:-1]
headers = {
‘Authorization’: auth_token
}
print(’[Authorization]:’,auth_token)
resp_ass_total = requests.get(url_ass_total, headers=headers)
print(’[总数]:’,resp_ass_total.json())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值