import pyautogui import time import sys import argparse import json __author__ = 'm3x1m0m' class RangeError(RuntimeError): def __init__(self, imsg): self.msg = imsg class c_j: def __init__(self, fname): self.fname = fname self.__read_settings() def __read_settings(self): with open(self.fname, "r") as rf: self.settings = json.load(rf) def __write_settings(self): with open(self.fname, "w") as wf: json.dump(self.settings, wf, indent=4, sort_keys=True) class c_learner(c_j): def __init__(self, fname): super().__init__(fname) def __wait(self, period): for t in range(0, period): print("{}".format(period-t)) time.sleep(1.0) def button(self, which): if not which in ["backward", "forward"]: raise RangeError("Wrong button type!") print("Go to the {} button".format(which)) self.__wait(5) currentMouseX, currentMouseY = pyautogui.position() print("x>{} y>{}".format(currentMouseX, currentMouseY)) self.settings["buttons"][which] = (currentMouseX, currentMouseY) self.__write_settings() class c_grabber(c_j): def __init__(self, fname): super().__init__(fname) def next_page(self, direction): if not direction in ["backward", "forward"]: raise RangeError("Direction does not exist.") pyautogui.click(self.settings[which][0], self.settings[which][1]) if __name__ == "__main__": parser = argparse.ArgumentParser(description="I don't like J.") parser.add_argument("-f","--file", help="JSON file where settings are stored.", required=True) parser.add_argument("-a", "--forward", help="Store forward button position.", action="store_true") parser.add_argument("-b", "--backward", help="Store backward button position.", action="store_true") # Parse args = parser.parse_args() if len(args.file) > 0: pupil = c_learner(args.file) if args.forward: pupil.button("forward") if args.backward: pupil.button("backward") if args.blattern: taker = c_grabber(args.file) while(1): taker.next_page("forward") time.sleep(1)