-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapelessstarbattle.py
49 lines (43 loc) · 1.92 KB
/
shapelessstarbattle.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
import subprocess
import time
import requests
import bs4
def pst():
with requests.Session() as session:
response = session.get('https://www.puzzle-star-battle.com/?size=13')
# session.cookies.set('api_token', 'NmG4oWK8XPBfoOnACvF11ZGsUJ00GkmVkZJw6lkdreS5nkKOXOoO1WGGNAe3')
response.raise_for_status()
a = bs4.BeautifulSoup(response.text, 'html.parser')
param = ''
b = ''
w = ''
h = ''
size = ''
for fld in a.find('form').find_all('input'):
if 'name' in fld.attrs:
if fld['name'] == 'param':
param = fld['value']
if fld['name'] == 'b':
b = fld['value']
if fld['name'] == 'w':
w = fld['value']
if fld['name'] == 'h':
h = fld['value']
if fld['name'] == 'size':
size = fld['value']
task = response.text.split('var task = \'')[1].split('\'')[0]
st=time.time()
ad=subprocess.run(['./ShapelessStarBattle'],input=(task+'\n'+str(w)+"\n1").encode(), capture_output=True)
ans=ad.stdout.decode('ascii').strip('\n')
res=session.post('https://www.puzzle-star-battle.com/',data=[("param",param),("b",b),("w",w),("h",h),("size",size),("ansH",ans),("robot","1"),("ready","+++Done+++")])
par=res.text.split('solparams" value="')[1].split('"')[0]
print(par)
# open("res.html",'w').write(res.text)
# a=session.post('https://www.puzzle-star-battle.com/hallsubmit.php',data=[("solparams",par),("robot","1")])
a=session.post('https://www.puzzle-star-battle.com/hallsubmit.php',data=[("solparams",par),("robot","1"),("email","[email protected]"),("submitscore","1")])
# open("asdf.html",'w').write(a.text)
res.raise_for_status()
print(a.status_code)
return task, ans
for i in range(10):
pst()