-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
84 lines (66 loc) · 2.01 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@author: xuxingyuan
@license: (C) Copyright 2013-2018, Node Supply Chain Manager Corporation Limited.
@software: yrx
@file: utils.py
@time: 2020/10/16 20:57
@desc:
'''
import pprint
import math
import hashlib
import time
import requests
def hex_md5(str):
return hashlib.md5(str.encode()).hexdigest()
def get_timestamp():
timestamp = math.floor(time.time()) * 1000
return timestamp
def str_2_headers(file):
headers = {}
with open(file) as f:
l = f.readline()
while l:
k_v = l.split(":", 1)
headers[k_v[0].strip()] = k_v[1].strip().replace('\n','')
l = f.readline()
pprint.pprint(headers)
def str_2_cookies(str):
cookie = {}
k_vs = str.split(';')
for k_v in k_vs:
k, v = k_v.split('=', 1)
cookie[k.strip()] = v.strip()
return cookie
import time
import base64
def btoa(str):
# timestamp = str(int(time.time()))
# a = '8808'
b = base64.encodebytes(str.encode("utf8"))
tokens = b.decode("utf8").strip()
return tokens
def yrf_login():
url = 'http://match.yuanrenxue.com/api/login'
data = {'username':'mix2plus',
'password': 'Yrx@2020'}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.90 Safari/537.36'}
s = requests.session()
r = s.post(url, data=data, headers=headers)
print(r.json())
url = 'http://match.yuanrenxue.com/api/loginInfo'
r = s.get(url, data=data, headers=headers)
# print(r.json())
# print(s.cookies)
return s
def avg(ls):
ls_int = [float(i) for i in ls]
return sum(ls_int)/len(ls_int)
if __name__ == '__main__':
# pprint.pprint(str_2_headers('resources/headers.txt'))
# pprint.pprint(str_2_cookies('Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1602903223; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1602903223; sessionid=tv10se9un5b1k3nj0msspkrba55ixd59'))
# print(get_timestamp())
# yrf_login()
print(btoa('password'))