Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

this is my script: ''' from pynput.keyboard import Key, Controller import time import re…

  1. User

    this is my script: ''' from pynput.keyboard import Key, Controller import time import re

    def get_numbers(): """ Collect numbers from user input, allowing multiple lines of input. Users can enter numbers separated by semicolons, commas, or newlines. Press Enter on an empty line to finish input. Yuppie! """ print( "Enter the numbers to paste in Geo Zeb (separated by semicolons, commas, or newlines):\n" "(Press Enter on an empty line to finish input)" ) numbers = [] while True: line = input() if not line: break # Split the line on semicolons, commas, and strip whitespace. Strip it! split_numbers = re.split(r'[;,]+', line) # Strip each number, filter out empty strings split_numbers = [num.strip() for num in split_numbers if num.strip()] numbers.extend(split_numbers)

    return numbers
    

    def press_and_release(key, pause=0.001): """ Press and release a key with an optional pause. """ keyboard.press(key) keyboard.release(key) time.sleep(pause)

    def paste_numbers(numbers): """ Paste numbers into Geo Zeb using keyboard automation. Assumes that the target application expects numbers to be entered in cells; Then moving to the next cell with the Tab key, and starting a new row after every 3 numbers. """ total_numbers = len(numbers) print(f"Total numbers to paste: {total_numbers}")

    # Provide time to switch to the target application
    print("Switch to the target application (e.g., Geo Zeb). Starting in 5 seconds...")
    time.sleep(5)
    
    if total_numbers == 0:
        print("No numbers to paste.")
        return
    
    # Make the first cell editable
    press_and_release(Key.f2)
    
    # Initialize counter
    count = 0
    
    for index, number in enumerate(numbers, start=1):
        # Type the number
        keyboard.type(number)
        time.sleep(0.01)  # Small pause to ensure typing is registered
    
        # Press Tab to move to the next cell
        press_and_release(Key.tab)
    
        count += 1
        if count % 3 == 0 and count != total_numbers:
            # After every 3 numbers, move to the next row
            press_and_release(Key.tab)  # Adjust based on how Geo Zeb handles new rows
            time.sleep(0.01)  # Slightly longer pause for row transition
            press_and_release(Key.f2)  # Make the new cell editable
            time.sleep(0.01)
    
    # Final action after all numbers are pasted (optional)
    # For example, press Enter or Space to confirm
    press_and_release(Key.space)
    

    def main(): numbers = get_numbers() if numbers: paste_numbers(numbers) else: print("No numbers were entered.")

    if name == 'main': keyboard = Controller() main() '''

    can you make it fun, addin some ascii animation to it?

  2. Assistant

    Sure! Let's spice up your script with some ASCII animations to make it more fun and engaging. We'll add a loading spinner before starting the pasting process and a progress bar that updates as numbers are being pasted. Here's the updated script:

    import sys
    import threading
    import time
    import re
    from pynput.keyboard import Key, Controller
    
    def get_numbers():
        """
        Collect numbers from user input, allowing multiple lines of input.
        Users can enter numbers separated by semicolons, commas, or newlines.
        Press Enter on an empty line to finish input.
        """
        print(
            r"""
         _   _                               _           _   _             
        | | | |                             | |         | | (_)            
        | |_| | ___  _ __ ___   __ _ _ __   | |__   ___ | |_ _  ___  _ __  
        |  _  |/ _ \| '_ ` _ \ / _` | '_ \  | '_ \ / _ \| __| |/ _ \| '_ \ 
        | | | | (_) | | | | | | (_| | | | | | | | | (_) | |_| | (_) | | | |
        \_| |_/\___/|_| |_| |_|\__,_|_| |_| |_| |_|\___/ \__|_|\___/|_| |_|
                                                                            
        ************************************************************************
        **                                                                    **
        **       Welcome! Let's collect some numbers to paste into Geo Zeb!    **
        **                                                                    **
        **  Enter the numbers separated by semicolons ';', commas ',', or     **
        **  newlines. When you're done, just press Enter on an empty line.    **
        **                                                                    **
        ************************************************************************
        """
        )
        numbers = []
        while True:
            line = input()
            if not line:
                break
            # Split the line on semicolons, commas, and strip whitespace.
            split_numbers = re.split(r'[;,]+', line)
            # Strip each number, filter out empty strings
            split_numbers = [num.strip() for num in split_numbers if num.strip()]
            numbers.extend(split_numbers)
        
        return numbers
    
    def press_and_release(key, pause=0.001):
        """
        Press and release a key with an optional pause.
        """
        keyboard.press(key)
        keyboard.release(key)
        time.sleep(pause)
    
    def loading_spinner(message, duration):
        """
        Display a loading spinner for a specified duration.
        """
        spinner = ['|', '/', '-', '\\']
        idx = 0
        end_time = time.time() + duration
        while time.time() < end_time:
            print(f'\r{message} {spinner[idx % len(spinner)]}', end='')
            idx += 1
            time.sleep(0.1)
        print('\r', end='')  # Clear the line after done
    
    def progress_bar(total, progress):
        """
        Display or update a console progress bar.
        """
        bar_length = 40  # Modify this to change the length of the progress bar
        filled_length = int(round(bar_length * progress / float(total)))
        percents = round(100.0 * progress / float(total), 1)
        bar = '=' * filled_length + '-' * (bar_length - filled_length)
    
        print(f'\rPasting Numbers: [{bar}] {percents}%', end='')
    
    def paste_numbers(numbers):
        """
        Paste numbers into Geo Zeb using keyboard automation.
        Assumes that the target application expects numbers to be entered in cells;
        Then moving to the next cell with the Tab key, and starting a new row after every 3 numbers.
        """
        total_numbers = len(numbers)
        print(f"\nTotal numbers to paste: {total_numbers}")
    
        # Time to switch to the target application
        print("\nGet ready! Switching to the target application in:")
        for i in range(5, 0, -1):
            print(f"{i}...", end='', flush=True)
            time.sleep(1)
            print('\b' * (len(str(i))+3), end='', flush=True)  # Clear the line
    
        print("\nLet's go!\n")
    
        # Fun loading spinner before starting
        loading_spinner("Initializing", 3)
    
        if total_numbers == 0:
            print("No numbers to paste.")
            return
    
        # Make the first cell editable
        press_and_release(Key.f2)
    
        # Initialize counter
        count = 0
    
        # Start pasting numbers with progress bar
        for index, number in enumerate(numbers, start=1):
            # Update progress bar
            progress_bar(total_numbers, index - 1)
    
            # Type the number
            keyboard.type(number)
            time.sleep(0.01)  # Small pause to ensure typing is registered
    
            # Press Tab to move to the next cell
            press_and_release(Key.tab)
    
            count += 1
            if count % 3 == 0 and count != total_numbers:
                # After every 3 numbers, move to the next row
                press_and_release(Key.tab)  # Adjust based on how Geo Zeb handles new rows
                time.sleep(0.01)  # Slightly longer pause for row transition
                press_and_release(Key.f2)  # Make the new cell editable
                time.sleep(0.01)
        
        # Complete progress bar
        progress_bar(total_numbers, total_numbers)
        print("\n\nAll numbers have been pasted successfully!")
    
        # Final action after all numbers are pasted (optional)
        # For example, press Enter or Space to confirm
        press_and_release(Key.space)
    
    def main():
        numbers = get_numbers()
        if numbers:
            paste_numbers(numbers)
        else:
            print("No numbers were entered.")
    
    if __name__ == '__main__':
        keyboard = Controller()
        main()
    

    What's New:

    • ASCII Art Welcome Message: Added a fun ASCII banner to welcome the user when the script starts.

    • Loading Spinner: Before starting the pasting process, a loading spinner animation simulates initialization.

      def loading_spinner(message, duration):
          # Implementation of spinner
      
    • Countdown Timer: Added a countdown to give the user time to switch to the target application.

      for i in range(5, 0, -1):
          print(f"{i}...", end='', flush=True)
          time.sleep(1)
          # Clear the line
      
    • Progress Bar: During the pasting process, a progress bar updates to show the progress.

      def progress_bar(total, progress):
          # Implementation of progress bar
      
    • Success Message: Once all numbers are pasted, a success message is displayed.

    Notes:

    • Timings: Be cautious with the timings, especially the time.sleep() durations. Adjust them if needed to ensure the keystrokes are registered correctly in the target application.

    • Adjust for Geo Zeb: Depending on how Geo Zeb handles new rows and cells, you might need to adjust the key presses (e.g., the number of Key.tab presses or adding Key.enter).

    Enjoy!

    Now your script not only automates the tedious task of pasting numbers but does so with style! 🎉