first_project
This commit is contained in:
49
check_plant_data.py
Normal file
49
check_plant_data.py
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
import mysql.connector
|
||||
|
||||
def get_connection_details():
|
||||
details = {}
|
||||
with open('setting.txt', 'r') as f:
|
||||
for line in f:
|
||||
key, value = line.strip().split(':', 1)
|
||||
details[key.strip()] = value.strip()
|
||||
return details
|
||||
|
||||
def check_plant_data():
|
||||
conn = None
|
||||
try:
|
||||
config = get_connection_details()
|
||||
conn = mysql.connector.connect(
|
||||
host=config.get('Host'),
|
||||
port=config.get('Port'),
|
||||
user=config.get('Username'),
|
||||
password=config.get('Password'),
|
||||
database=config.get('Database')
|
||||
)
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("SELECT id, plant, department, name, extension FROM extension_data LIMIT 10")
|
||||
rows = cursor.fetchall()
|
||||
|
||||
if not rows:
|
||||
print("No data found in extension_data table.")
|
||||
return False
|
||||
|
||||
print("First 10 rows of extension_data:")
|
||||
for row in rows:
|
||||
print(row)
|
||||
if row.get('plant') is None or row.get('plant') == '':
|
||||
print("'plant' column contains empty or NULL values. Data might be missing.")
|
||||
return False
|
||||
print("'plant' column seems to have data.")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return False
|
||||
finally:
|
||||
if conn and conn.is_connected():
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_plant_data()
|
Reference in New Issue
Block a user