From 326ead47cad6a3d763f2f3e976fac37287d3a66d Mon Sep 17 00:00:00 2001 From: frankknoll Date: Thu, 12 May 2022 19:44:06 +0200 Subject: [PATCH] refactoring --- src/HowBadIsMyBatch.ipynb | 45 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/HowBadIsMyBatch.ipynb b/src/HowBadIsMyBatch.ipynb index 23bf0e878ae..83cc5915bb6 100644 --- a/src/HowBadIsMyBatch.ipynb +++ b/src/HowBadIsMyBatch.ipynb @@ -138,41 +138,34 @@ "source": [ "import os\n", "\n", - "def startEmulator():\n", - " os.system(\"/home/frankknoll/Android/Sdk/emulator/emulator -avd Pixel_2_API_30 -no-window &\")\n", + "class Emulator:\n", " \n", - "def stopEmulator():\n", - " ! adb emu kill" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fb3755a6", - "metadata": {}, - "outputs": [], - "source": [ - "startEmulator()" + " @staticmethod\n", + " def runWithinEmulator(runnable):\n", + " Emulator._startEmulator()\n", + " result = runnable()\n", + " Emulator._stopEmulator()\n", + " return result\n", + " \n", + " @staticmethod\n", + " def _startEmulator():\n", + " os.system(\"/home/frankknoll/Android/Sdk/emulator/emulator -avd Pixel_2_API_30 -no-window &\")\n", + "\n", + " @staticmethod\n", + " def _stopEmulator():\n", + " ! adb emu kill\n" ] }, { "cell_type": "code", "execution_count": null, "id": "c113e49d", - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [], "source": [ - "textInImage = detectTextInImage(captchaImageFile)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cdf3fbe1", - "metadata": {}, - "outputs": [], - "source": [ - "stopEmulator()" + "textInImage = Emulator.runWithinEmulator(lambda: detectTextInImage(captchaImageFile))" ] }, {