Python - enter random chars to a field

Hi Everyone,
hope you have a great day :slight_smile:

Below is a Python code to enter random chars to a field.
I’ve already find a way to optimize it.
But that’s story for a next post :wink:

BTW
Why there is no tag:
Python, script, programing

from seatable_api import Base, context
import random
import string

# Table and column configuration
TABLE_NAME = "Maile przychodzace"  # Replace with your table name
COLUMN_NAME = "Tresc"

# Initialize SeaTable API
base = Base(context.api_token, context.server_url)
base.auth()

# Function to generate a string of specified length
def generate_long_text(length):
    # Sample text to repeat
    sample_text = ''.join(random.choices(string.ascii_letters, k=1000))
    # Calculate how many times to repeat and handle remainder
    repeats = length // len(sample_text) + 1
    long_text = (sample_text * repeats)[:length]
    return long_text

def main():
    try:
        # Generate 90,000 characters
        text = generate_long_text(90000)
        
        # Create row data
        row_data = {
            COLUMN_NAME: text
        }
        
        # Append the row to the table
        base.append_row(TABLE_NAME, row_data)
        print(f"Successfully added a row with 90,000 characters to the '{COLUMN_NAME}' column in '{TABLE_NAME}'.")
        
    except Exception as e:
        print(f"Error occurred: {e}")

if __name__ == "__main__":
    main()

Hi @dece, welcome to the SeaTable forum, and thanks for your script!

I allowed myself to:

  • set the Scripts (Python and JS) tag (as you see it exists actually!)
  • modify your script formatting using the triple simple quote (```) to display the whole code as a block (use simple quote for inline code)

Bests,
Benjamin