def start(self): self.webpage_image_update_interval = Config.getfloat( "Gui", "webpage_image_update_interval") self.install_dependants() self.setup() self.start_webpage_image_updater() self.do_webpage_image_update = True self.pre_mine() self.mine() self.do_webpage_image_update = False self.post_mine()
class _Miner(EventDispatcher): usrName = StringProperty("") pwdInput = StringProperty("") stopOnlyWhenStopPressed = BooleanProperty(False) mineUntilPoints = NumericProperty(None) mineForTime = NumericProperty(None) requireAll = BooleanProperty(True) midLinePos = NumericProperty(0) webpage_image_update_interval = Config.getfloat( "Gui", "webpage_image_update_interval") do_webpage_image_update = False driver = None Gui = None def start(self): self.webpage_image_update_interval = Config.getfloat( "Gui", "webpage_image_update_interval") self.install_dependants() self.setup() self.start_webpage_image_updater() self.do_webpage_image_update = True self.pre_mine() self.mine() self.do_webpage_image_update = False self.post_mine() def start_webpage_image_updater(self): Thread(target=self.webpage_image_updater, daemon=True).start() def webpage_image_updater(self): while True: if self.do_webpage_image_update: t = time.time() Logger.debug("WebpageImage: Starting image update") data = io.BytesIO(self.driver.get_screenshot_as_png()) coreImage = CoreImage(data, ext="png") Clock.schedule_once( lambda _: self.Gui.update_webpage_image(coreImage, t), 0) try: time.sleep(self.webpage_image_update_interval - (time.time() - t)) except ValueError: Logger.warning( "WebpageImage: Convert took to long, took " + str(time.time() - t) + " and it should've took " + str(self.webpage_image_update_interval)) else: time.sleep(self.webpage_image_update_interval) def install_dependants(self): chromedriver_autoinstaller.install() Logger.info("Miner: Chromedriver installed if not already") def setup(self): try: self.driver.quit() except AttributeError: pass chromedriver_autoinstaller.install() Logger.info("Miner: Chromedriver installed if not already") chrome_options = ChromeOptions() if Config.getboolean("Gui", "headless"): chrome_options.add_argument("--headless") chrome_options.add_argument("--window-size=1920,1080") chrome_options.add_argument( "--log-path=" + str(os.path.join(user_data_dir, "chromedriver.log"))) Logger.info("Miner: Chromedriver setup") url = Config.get("URLs", "sign_in") self.driver = webdriver.Chrome(options=chrome_options) self.driver.get(url) Logger.info("Miner: Loaded " + str(url)) def pre_mine(self): Logger.info("Miner: Started pre mining setup function") MemriseElements.get("username_input", self.driver).send_keys(self.usrName) MemriseElements.get("password_input", self.driver).send_keys(self.pwdInput) MemriseElements.get("login_submit_button", self.driver).click() wait_till_page_load(self.driver) home_courses_elements = MemriseElements.get_multiple( "courses", self.driver) home_courses = {} for course in home_courses_elements: home_courses[str(MemriseElements.get("course_title", course).get_attribute("title"))] = \ MemriseElements.get("course_title", course).find_element(By.TAG_NAME, "a").get_attribute("href") Logger.info("Miner: Located courses and links: \n" + str(pformat(home_courses))) self.driver.get(Config.get("URLs", "groups")) groups_elements = MemriseElements.get_multiple( "groups_individual", MemriseElements.get("groups", self.driver)) groups_courses = {} for group in groups_elements: groups_courses[str( MemriseElements.get("groups_individual_title", group).text)] = {} for course in MemriseElements.get_multiple( "groups_individual_courses", group): groups_courses[str( MemriseElements.get( "groups_individual_title", group).text)][MemriseElements.get( "course_title", course).text] = MemriseElements.get( "course_title", course).find_element( By.TAG_NAME, "a").get_attribute("href") Logger.info("Miner: Located groups, courses and links: \n" + str(pformat(groups_courses))) Logger.info("Miner: Finished pre mining setup function") def mine(self): Logger.info("Miner: Started mining function") pass Logger.info("Miner: Finished mining function") def post_mine(self): self.driver.close()