This repository was archived by the owner on Oct 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbaidu_dog.py
58 lines (47 loc) · 1.66 KB
/
baidu_dog.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
# coding=utf-8
import json
import math
import requests
import time
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
c_cookies = 'BDUSS=XXX'
headers = {
'Host': 'pet-chain.baidu.com',
'Connection': 'keep-alive',
'Accept': 'application/json',
'Origin': 'https://pet-chain.baidu.com',
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Mobile Safari/537.36',
'Content-Type': 'application/json',
'Referer': 'https://pet-chain.baidu.com',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': c_cookies}
def recall(pet_id):
url = 'https://pet-chain.baidu.com/data/market/unsalePet'
timestamp = int(round(time.time() * 1000))
payload = {"petId": pet_id, "requestId": timestamp, "appId": 1, "tpl": ""}
res = requests.post(url, data=json.dumps(payload), headers=headers)
# return json.loads(res.content)['errorMsg']
emsg = json.loads(res.content)['errorMsg']
print '撤回: ' + emsg
return emsg
def sell(pet_id, amount):
url = 'https://pet-chain.baidu.com/data/market/salePet'
timestamp = int(round(time.time() * 1000))
payload = {"petId": pet_id, "amount": amount, "requestId": timestamp, "appId": 1, "tpl": ""}
res = requests.post(url, data=json.dumps(payload), headers=headers)
emsg = json.loads(res.content)['errorMsg']
print '以' + str(amount) + '售出: ' + emsg
petId = "XXX"
while True:
sell(petId, 1499)
time.sleep(0.3)
recall(petId)
sell(petId, 19999)
time.sleep(10)
msg = recall(petId)
if "有人购买" in msg:
break
time.sleep(2)