Python Forum
Help | Classes to use in real world
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help | Classes to use in real world
#5
In this example, you could start using a class to decompose the different actions into smaller units with an expressive name. I don't understand all the code because I don't use pyautogui, but you could start from here
import pyautogui as pag

class Agent:
    def run(self):
        """Main agent's action"""
        self.call_chrome()
        self.scroll_to_second_section()
        self.click_to_sort_ranking()
        self.fire_up_nimbus()
        self.screenshot_page()
    
    def call_chrome(self):
        # TODO: decompose this into smaller units
        pag.hotkey('command', 'space')
        pag.typewrite('Chrome\n', 0.25)
        pag.moveTo(412, 81, duration=2)
        pag.click(button='left')
        pag.typewrite('target_site_example.com\n')
        pag.moveTo(927, 431, duration=5)
        pag.click(button='left')
        pag.moveTo(286, 132, duration=5)
        pag.click(button='left')
        pag.click(button='left')
        pag.moveTo(1206, 946, duration=5)
        pag.click(button='left')
        pag.moveTo(1797, 587, duration=5)
        pag.click(button='left')
        
        pag.moveTo(768, 137)
        pag.click(button='left')
        
    def scroll_to_second_section(self):
        pag.scroll(-50)
        
    def click_to_sort_ranking(self):
        pag.moveTo(1189, 735, duration=5)
        pag.click(button='left')
        
    def fire_up_nimbus(self):
        pag.moveTo(1146, 84, duration=5)
        pag.click(button='left')
        
    def screenshot_page(self):
        pag.moveTo(995, 331, duration=5)
        pag.click(button='left')

if __name__ == '__main__':
    pag.FAILSAFE=True
    a = Agent()
    a.run()
Of course, it's only the beginning.
Reply


Messages In This Thread
RE: Help | Classes to use in real world - by Gribouillis - Jul-06-2019, 08:42 AM
RE: Help | Classes to use in real world - by nilamo - Jul-08-2019, 07:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  World Clock syntax error OscarBoots 1 35 1 hour ago
Last Post: snippsat
  Hello World! rufenghk 0 977 Jun-02-2022, 09:48 PM
Last Post: rufenghk
  Very new to Python world daveseaman 0 1,494 Jun-25-2021, 07:17 PM
Last Post: daveseaman
  running python hello world Avarage_Joe 8 5,310 Apr-13-2018, 04:20 PM
Last Post: Avarage_Joe
  Hello world! program, window disappears nerio 3 5,663 Mar-16-2018, 07:03 PM
Last Post: knackwurstbagel
  Using classes? Can I just use classes to structure code? muteboy 5 5,099 Nov-01-2017, 04:20 PM
Last Post: metulburr
  'Hello, World!' Problem - Urgent OmarSinno 7 4,636 Sep-07-2017, 06:22 AM
Last Post: OmarSinno
  how to generate random 3d world (like minecraft) in python hsunteik 3 104,269 Jan-06-2017, 06:35 PM
Last Post: metulburr
  Hello World issues when using %% with ipython landlord1984 5 8,971 Dec-11-2016, 10:11 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020