import sys import time import sqlite3 try: amount_of_deals = sys.argv[1] pair = None if len(sys.argv) > 2: pair = sys.argv[2] except Exception as e: print(e) print("Usage: python3 last_n_deals.py int ") sys.exit() connection = sqlite3.connect('profits_database.db') cursor = connection.cursor() extra_query = "" if pair: extra_query = f"WHERE pair = '{pair}'" cursor.execute(f'SELECT * FROM profits_table {extra_query} ORDER BY timestamp DESC LIMIT ?', (amount_of_deals,)) deals = cursor.fetchall() connection.close() for line in deals[::-1]: human_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(line[0]))) print(human_time,line[1],round(line[2],2),line[3])