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