CryptoMarketParser/utils/drop_data.py
2025-03-18 10:13:37 +08:00

37 lines
949 B
Python

import sqlite3
from datetime import datetime
# Specify the database file path
db_path = 'bitcoin_historical_data.db'
# Create a connection to the database
connection = sqlite3.connect(db_path)
# Create a cursor object
cursor = connection.cursor()
# Define the date threshold
date_threshold = datetime(2025, 1, 15)
# Convert the date threshold to the format used in SQLite (YYYY-MM-DD HH:MM:SS.SSS)
date_threshold_str = date_threshold.strftime('%Y-%m-%d 00:00:00.000')
# SQL query to delete rows with Timestamp greater than the date threshold
query = """
DELETE FROM bitcoin_data
WHERE Timestamp > ?
"""
# Execute the query with the date threshold as a parameter
cursor.execute(query, (date_threshold_str,))
# Commit the changes
connection.commit()
# Get the number of deleted rows
deleted_rows = cursor.rowcount
print(f"Deleted {deleted_rows} rows with Timestamp greater than January 15th, 2025")
# Close the connection
connection.close()