Files
xbot-market-info/market-data-analyse.py
2024-12-24 21:04:13 +08:00

47 lines
1.3 KiB
Python

import mysql.connector
# Database connection parameters
db_host = "172.18.240.115"
db_port = "3306"
db_user = "root"
db_password = "VaDS4mrgKoJi"
db_name = "xbot_market_info"
# Connect to MySQL database
conn = mysql.connector.connect(
host=db_host, port=db_port, user=db_user, password=db_password, database=db_name
)
cursor = conn.cursor()
# Define your query to get total row count
count_query = "SELECT COUNT(*) FROM rpa_app_scene_info"
cursor.execute(count_query)
total_rows = cursor.fetchone()[0]
# Pagination parameters
batch_size = 1000 # Number of rows to fetch in each batch
total_batches = (total_rows // batch_size) + 1 # Total number of batches to fetch
# Open the output file in write mode
with open("data.txt", "w") as f:
for batch_num in range(total_batches):
offset = batch_num * batch_size
# Define your query with pagination
query = f"SELECT biz_id, biz_sub_id, scene_info FROM rpa_app_scene_info LIMIT {batch_size} OFFSET {offset}"
# Execute the query
cursor.execute(query)
# Fetch results for the current batch
results = cursor.fetchall()
# Write the results to the file
for row in results:
f.write(f"{row[0]},{row[1]},{row[2]}\n")
# Clean up
cursor.close()
conn.close()
print("Data has been written to data.txt.")