Created
March 3, 2016 14:19
-
-
Save ripples-alive/df2efb24ee45a1db3b92 to your computer and use it in GitHub Desktop.
scripts for yunfarm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding:utf-8 | |
import time | |
import requests | |
session = requests.Session() | |
base_url = 'http://m.yunfarm.cn' | |
# login | |
url = base_url + '/api/v2/session' | |
params = { | |
'mobile': '18888888888', | |
'password': 'cbd41c6103064d3f0af848208c20ece2', # md5(password) | |
} | |
token = session.post(url, data=params).json()['token'] | |
# get batch info | |
url = base_url + '/api/batch/batchInfo' | |
params = { | |
'access_token': token, | |
} | |
batch_info = session.get(url, params=params).json() | |
# print batch_info | |
if not batch_info['batches']: | |
print 'no batch:', batch_info | |
exit() | |
batch_info = batch_info['batches'][0] | |
batch_id = batch_info['_id'] | |
url = base_url + '/api/order/rank' | |
params = { | |
'access_token': token, | |
'batch_id': batch_id, | |
'limit': batch_info['total_num'], | |
'skip': 0, | |
} | |
rank_infos = session.get(url, params=params).json()['rank_infos'] | |
print sum(map(lambda x: x['sheep_num'], rank_infos)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding:utf-8 | |
import time | |
import requests | |
session = requests.Session() | |
base_url = 'http://m.yunfarm.cn' | |
aim = 10 | |
split = 2 | |
# login | |
url = base_url + '/api/v2/session' | |
params = { | |
'mobile': '18888888888', | |
'password': 'cbd41c6103064d3f0af848208c20ece2', # md5(password) | |
} | |
token = session.post(url, data=params).json()['token'] | |
while True: | |
# get batch info | |
url = base_url + '/api/batch/batchInfo' | |
params = { | |
'access_token': token, | |
} | |
batch_info = session.get(url, params=params).json() | |
if not batch_info['batches']: | |
# print 'no batch:', batch_info | |
continue | |
batch_info = batch_info['batches'][0] | |
batch_id = batch_info['_id'] | |
limit = batch_info['limit']['orderSheepNum'] | |
unsell = batch_info['total_num'] - batch_info['sell_num'] | |
sheep_num = min(unsell / split, aim, limit) | |
if sheep_num == 0: | |
continue | |
print sheep_num, unsell / split, aim, limit | |
for i in xrange(split): | |
# create order | |
last_time = int(time.time() * 1000) | |
url = base_url + '/api/order/job' | |
params = { | |
'access_token': token, | |
'last_time': last_time, | |
} | |
body = { | |
"popBg": True, | |
"sheep_num": sheep_num, | |
"batch_id": batch_id, | |
"last_time": last_time | |
} | |
print session.post(url, params=params, json=body).content | |
job_id = session.post(url, params=params, json=body).json() | |
if 'jobId' not in job_id: | |
print 'no job:', job_id | |
continue | |
job_id = job_id['jobId'] | |
# check order state | |
url = base_url + '/api/order/job/%d/state' % job_id | |
params = { | |
'access_token': token, | |
} | |
print sheep_num, ':', job_id, '=>', session.get(url, params=params).content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment