various fixes
This commit is contained in:
parent
d87f1f7886
commit
f6c6c6c66e
18
bot.py
18
bot.py
@ -88,11 +88,10 @@ class State:
|
|||||||
def restore(self):
|
def restore(self):
|
||||||
# use yesterday's state if available
|
# use yesterday's state if available
|
||||||
# if not, use the latest previous
|
# if not, use the latest previous
|
||||||
files = b2.list_objects(self.bucket_id, 'wordle/')
|
files = self.b2_client.list_objects(self.bucket_id, 'wordle/')
|
||||||
data = None
|
data = None
|
||||||
for i in range(1, 1001):
|
for filename in reversed(files):
|
||||||
filename = files[-i]
|
if filename < f'state_{datetime.date.today()}.json':
|
||||||
if filename < f'state_{datetime.date().today()}.json':
|
|
||||||
data = self.b2_client.get_object('cupboard', filename)
|
data = self.b2_client.get_object('cupboard', filename)
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -101,24 +100,25 @@ class State:
|
|||||||
"window.localStorage.setItem('statistics', arguments[1]);",
|
"window.localStorage.setItem('statistics', arguments[1]);",
|
||||||
data.decode('utf-8')
|
data.decode('utf-8')
|
||||||
)
|
)
|
||||||
print('Restored state: ' filename)
|
print('Restored state: ', filename)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
state = self.driver.execute_script("return window.localStorage.getItem('statistics')")
|
state = self.driver.execute_script("return window.localStorage.getItem('statistics')")
|
||||||
if state:
|
if state:
|
||||||
filename = f'state_{datetime.date().today()}.json'
|
filename = f'state_{datetime.date.today()}.json'
|
||||||
self.b2_client.put_object(
|
self.b2_client.put_object(
|
||||||
self.bucket_id,
|
self.bucket_id,
|
||||||
'wordle_state.json',
|
f'wordle/{filename}',
|
||||||
state.encode('utf-8')
|
state.encode('utf-8')
|
||||||
)
|
)
|
||||||
print('Saved state: ' filename)
|
print('Saved state: ', filename)
|
||||||
|
|
||||||
|
|
||||||
class Solver:
|
class Solver:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print('Launching web browser')
|
print('Launching web browser')
|
||||||
self.driver = self.setup_driver()
|
self.driver = self.setup_driver()
|
||||||
|
self.state = State(self.driver)
|
||||||
print('Navigating to page')
|
print('Navigating to page')
|
||||||
self.driver.get('https://www.powerlanguage.co.uk/wordle/')
|
self.driver.get('https://www.powerlanguage.co.uk/wordle/')
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
@ -224,7 +224,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if result:
|
if result:
|
||||||
print(f'Success!')
|
print(f'Success!')
|
||||||
else
|
else:
|
||||||
print('Failed to find the word.')
|
print('Failed to find the word.')
|
||||||
|
|
||||||
wordle_num = (datetime.date.today() - datetime.date(2022, 1, 17)).days + 212
|
wordle_num = (datetime.date.today() - datetime.date(2022, 1, 17)).days + 212
|
||||||
|
Loading…
x
Reference in New Issue
Block a user