Created
August 22, 2018 02:31
-
-
Save fabito/2b9dfd44fc38ea5a9cf65447c80906c6 to your computer and use it in GitHub Desktop.
neyboy game - get_state method
This file contains hidden or 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
async def get_state(self): | |
state = await self.page.evaluate('''(includeSnapshot, format, quality) => { | |
return neyboyChallenge.state(includeSnapshot, format, quality); | |
}''', True, 'image/jpeg', 30) | |
base64_string = state['snapshot'] | |
base64_string = re.sub('^data:image/.+;base64,', '', base64_string) | |
imgdata = base64.b64decode(base64_string) | |
bytes_io = io.BytesIO(imgdata) | |
image = Image.open(bytes_io) | |
state['snapshot'] = np.array(image) | |
self.state = GameState(**state) | |
return self.state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment