Skip to content

Instantly share code, notes, and snippets.

@mzhang77
Created June 20, 2025 00:56
Show Gist options
  • Select an option

  • Save mzhang77/2a0a0f79595996dfa0a00e72ec56cf6c to your computer and use it in GitHub Desktop.

Select an option

Save mzhang77/2a0a0f79595996dfa0a00e72ec56cf6c to your computer and use it in GitHub Desktop.
import random
import string
import datetime
import mysql.connector
import time
def random_string(length=10):
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))
def random_date(start_year=2000, end_year=2025):
start = datetime.date(start_year, 1, 1)
end = datetime.date(end_year, 12, 31)
return start + datetime.timedelta(days=random.randint(0, (end - start).days))
def random_datetime():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Connect to your database
conn = mysql.connector.connect(
host="ac45cd69eca6a42b5a2950a83d351d99-05eeace4ee462b35.elb.us-east-2.amazonaws.com",
user="root",
port="4000",
database="test"
)
cursor = conn.cursor()
try:
while True:
data = {
'id': random_string(),
'object_id': random_string(),
'document_mapping_id': random_string(),
'external_document_id': random_string(),
'external_id': random_string(),
'metric_1': random.randint(0, 1000),
'metric_2': random_date(),
'metric_3': random.randint(0, 1000),
'field_39': random_string(),
'field_40': random_string(),
'numeric_1': round(random.uniform(0, 1000), 2),
'timestamp_1': random_datetime(),
'created_at': random_datetime(),
'updated_at': random_datetime(),
'customer_id': random_string(36),
'integration_id': random_string(36),
'object_type': 'contact',
'catalyst_id': random_string(64) # Primary key
}
query = """
INSERT INTO external_contact (
id, object_id, document_mapping_id, external_document_id, external_id,
metric_1, metric_2, metric_3, field_39, field_40,
numeric_1, timestamp_1, created_at, updated_at,
customer_id, integration_id, object_type, catalyst_id
) VALUES (
%(id)s, %(object_id)s, %(document_mapping_id)s, %(external_document_id)s, %(external_id)s,
%(metric_1)s, %(metric_2)s, %(metric_3)s, %(field_39)s, %(field_40)s,
%(numeric_1)s, %(timestamp_1)s, %(created_at)s, %(updated_at)s,
%(customer_id)s, %(integration_id)s, %(object_type)s, %(catalyst_id)s
)
"""
cursor.execute(query, data)
conn.commit()
print(f"Inserted row with catalyst_id: {data['catalyst_id']}")
# Optional sleep to avoid CPU hogging
#time.sleep(0.1)
except KeyboardInterrupt:
print("Stopped by user.")
except Exception as e:
print(f"Error occurred: {e}")
finally:
cursor.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment