Skip to content

Instantly share code, notes, and snippets.

@pbfy0
Last active April 14, 2017 00:33
Show Gist options
  • Save pbfy0/323e331202126f7676cec16fa5d13d42 to your computer and use it in GitHub Desktop.
Save pbfy0/323e331202126f7676cec16fa5d13d42 to your computer and use it in GitHub Desktop.
from collections import Counter
#import urrlib.request as ur
#import http.cookiejar
import requests
import time
import re
import json
import random
import traceback
import configparser
import sys
#mmm = dict([('_', None), ('a', 9), ('b', 3), ('c', 6), ('d', 7), ('e', 0), ('f', 1), ('g', 4), ('h', 8), ('i', 2), ('j', 0), ('k', 4), ('l', 6), ('m', 3), ('n', 7), ('o', 9), ('p', 6), ('q', 9), ('r', 1), ('s', 8), ('t', 4), ('u', 1), ('v', 6), ('w', 3), ('x', 5), ('y', 9), ('z', 7)])#dict(a=1, b=1, c=3, d=2, e=4, f=7)
#sss = 'abcdefghijjklmnopqrstuvwxyz'
#options_a = [ 31 , 15 , 30 , 21 , 2 , 1 ,]#Counter(mmm[x] for x in options_a)
#options_b = [ 74 , 74 , 89 , 89 , 74 , 74 ,]#set('abcdef')
hh = {'user-agent': 'Mozilla/5.0'}
config = configparser.ConfigParser()
config.read('config.ini')
a_jar = requests.cookies.RequestsCookieJar()
b_jar = requests.cookies.RequestsCookieJar()
a_jar.set('ANR', config['DEFAULT']['A_COOKIE'])
b_jar.set('ANR', config['DEFAULT']['B_COOKIE'])
#f = 2285030251
#correct_order = 'fadecb'
r_a = requests.get('https://metheus.dontstarvetogether.com', cookies=a_jar, headers=hh).text
#print(r_a)
f = int(re.search(r'var\s+f\s+=\s+(\d+)', r_a).group(1))
rrr_a = re.search(r'fillRightTablet\(\[(.*?),\],\s+\[(.*?),\],', r_a)
options_b = json.loads('[' + rrr_a.group(1) + ']')
all_a = json.loads('[' + rrr_a.group(2) + ']')
r_b = requests.get('https://metheus.dontstarvetogether.com', cookies=b_jar, headers=hh).text
rrr_b = re.search(r'fillRightTablet\(\[(.*?),\],\s+\[(.*?),\],', r_b)
options_a = json.loads('[' + rrr_b.group(1) + ']')
all_b = json.loads('[' + rrr_b.group(2) + ']')
print('f =', f)
print('options_a =', options_a)
print('options_b =', options_b)
slots_a = [0] * 6
slots_b = [0] * 6
def status(ck):
return requests.post('https://metheus.dontstarvetogether.com/progress', json={'f': f, 'rw': True}, cookies=ck, headers=hh).json()
#print(requests.post('https://metheus.dontstarvetogether.com/progress', json={'f': f, 'rw': True}, cookies=a_jar, headers=hh).text)
#print(requests.post('https://metheus.dontstarvetogether.com/progress', json={'f': f, 'rw': True}, cookies=b_jar, headers=hh).text)
as_ = status(a_jar)
if as_.get('Count', 0) == 6:
print('All good!')
input('Press enter to exit ')
sys.exit(0)
print(as_)
count = 0
def update(cookies, slots, all):
aa = [x for x in slots if x in all]
if len(aa) < 6: print('aaaaa', aa)
resp = requests.post('https://metheus.dontstarvetogether.com/progress', headers=hh, cookies=cookies, json={'combination': aa})
j = resp.json()
time.sleep(0.25)
#print(j)
global count
count = j.get('Count', 0)
total_as = 0
def update_a():
global total_as
total_as += 1
print('checking a', slots_a)
update(a_jar, slots_a, all_a)
total_bs = 0
def update_b():
global total_bs
total_bs += 1
print('checking b', slots_b)
update(b_jar, slots_b, all_b)
unknowns_a = set(options_a)
unknowns_b = Counter(options_b)
slots_left = set(range(6))
arb_a = None
for i in all_a:
if i not in options_a:
arb_a = i
break
arb_b = None
for i in all_b:
if i not in options_b:
arb_b = i
break
def split_set(s):
s2 = set()
n = len(s) // 2
for i in range(n):
s2.add(s.pop())
return s, s2
def smart_not_dumb():
mapping = sorted(zip(options_a, options_b), key=lambda x: x[1])
res_a = [None] * 6
res_b = [None] * 6
fb = None
for a, b in mapping:
if b != fb:
fb = b
slots_b[:] = [b] * 6
update_b()
tmp_left = set(slots_left)
def check(slots):
slots_a[:] = [arb_a] * 6
nonlocal a
for s in slots:
slots_a[s] = a
update_a()
return count > 0
while len(tmp_left) > 1:
p1, p2 = split_set(tmp_left)
if check(p1):
tmp_left = p1
else:
tmp_left = p2
p = tmp_left.pop()
#print(slots_left)
slots_left.remove(p)
res_a[p] = a
res_b[p] = b
print(res_a, res_b)
slots_a[:] = res_a
update_a()
slots_b[:] = res_b
update_b()
try:
smart_not_dumb()
except Exception:
print('Errored with: ')
print('A:', total_as, 'B:', total_bs, 'total:', total_as + total_bs)
raise
print(total_checks)
#print(correct_order)
print(slots_a)
print(slots_b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment