Results 1 to 1 of 1

Thread: [Python] Best way to organize code and handle scheduling for a NP multitool?

  1. #1
    Xanice's Avatar
    Joined
    Dec 2011
    Posts
    295
    Userbars
    5
    Thanks
    47
    Thanked
    138/90
    DL/UL
    3/0
    Mentioned
    46 times
    Time Online
    1d 4h 57m
    Avg. Time Online
    N/A

    [Python] Best way to organize code and handle scheduling for a NP multitool?

    Hey I'm back again!

    Not sure if anyone is too interested in the subject but I've actually just finished my first two prototypes of tools. I feel its fine to say that they are prototypes of a neopets autobuyer and auto shop pricer. The AB still has a TON of functionality I need to add, but for now its safe to say there's a loose "human haggle" code and a working timing function. My main objective outside of getting these done is to create a replica of a human player. Therefore, while these functions are individually important - the MOST important piece is actually the scheduler.

    In other words - how do I get this script to transition from one task to another in a human way?


    Currently, I'm running into the following issues with the scheduler:
    1) In order to login to neopets and keep my session, I need to retain cookies. I am using a Selenium library for python which allows me to do so, however, when I try to build it into a class it seems to error when i try to load via cookies (over using just normal code in a notebook). I assume classes and subclasses would be pivotal in creating clean and adaptable code - but I never properly learned how to create class structure. Does anyone have any feedback or material on what the best way to approach class creation is? Likely the way I'm setting up my class is interfering with the cookie retention in my opinion.

    2) My timer function currently uses a while loop that looks something like the below. Frankly I think its a terrible approach to timing, but its essentially used to runt he buying function at certain times of the day. There are two core problems I have with this approach. 1) Currently to stop the program I have to interrupt and restart the kernal and 2)this is relatively inflexible because if i want to schedule tasks outside of these time frames, the code can get very confusing very quickly. My goal is to create a scheduling priority. In example, lets say there was an autoplayer, a pet trainer, an autobuyer, and a shop wizard buyer function. I would want to be able to set what activities should take precedent over the other ones, and basically complete the other ones int he interim.

    Code:
    while True:
        current_time = datetime.datetime.now()
        if  current_time.minute % 6 == 0 and current_time.second % 60 == 0 and not ran_once:
           ##AB FUNCTI
            autobuyer() 
            ran_once = True
    
        elif current_time.minute % 6 == 0 or current_time.second % 60 != 0:
    
            if current_time.second % 60 == 0:
                print("Time to wait:", 6 - (current_time.minute % 6), "minutes and 0 seconds")
            else:
                print("Time to wait:", 5 - (current_time.minute % 6), "minutes and ", end="")
                print(60 - (current_time.second % 60), "seconds")
    
            time.sleep( (5 -(current_time.minute % 6))*60 + 60 -(current_time.second % 60))
    
            ran_once = False
    There's a lot of other parts I need to address too but these are the two parts that I am currently strugglging the most on. As always appreciate feedback from anybody who codes or scripts, regardless if the input is python specific.

    Thanks
    Last edited by Xanice; 04-23-2023 at 07:05 PM.


    Cause someday I'll be OVER 9,000... Rep!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •