git
This commit is contained in:
64
Systematicky/01 CozbyvádotáhnoutdleMysql.py
Normal file
64
Systematicky/01 CozbyvádotáhnoutdleMysql.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import pymysql
|
||||
import pymysql.cursors
|
||||
|
||||
|
||||
def get_unfinished_torrents():
|
||||
# Konfigurace připojení
|
||||
connection_config = {
|
||||
'host': '192.168.1.76',
|
||||
'user': 'root',
|
||||
'password': 'Vlado9674+',
|
||||
'database': 'torrents',
|
||||
'port': 3307,
|
||||
'cursorclass': pymysql.cursors.DictCursor # Vrací výsledky jako slovník
|
||||
}
|
||||
|
||||
try:
|
||||
# Navázání spojení
|
||||
connection = pymysql.connect(**connection_config)
|
||||
|
||||
with connection.cursor() as cursor:
|
||||
# SQL Dotaz
|
||||
sql = """
|
||||
SELECT
|
||||
title_visible,
|
||||
qb_progress,
|
||||
qb_state,
|
||||
size_pretty,
|
||||
added_datetime
|
||||
FROM torrents
|
||||
WHERE qb_added = 1
|
||||
AND qb_progress < 1
|
||||
AND qb_state NOT IN ('seeding', 'uploading', 'stalledUP', 'pausedUP', 'completed')
|
||||
ORDER BY qb_progress DESC;
|
||||
"""
|
||||
|
||||
cursor.execute(sql)
|
||||
results = cursor.fetchall()
|
||||
|
||||
print(f"\n--- NEDOKONČENÉ TORRENTY (Port {connection_config['port']}) ---")
|
||||
|
||||
if not results:
|
||||
print("Vše je hotovo nebo nic neběží.")
|
||||
else:
|
||||
for row in results:
|
||||
# Předpokládáme, že qb_progress je float (0.0 až 1.0)
|
||||
progress_pct = row['qb_progress'] * 100
|
||||
|
||||
print(f"Torrent: {row['title_visible']}")
|
||||
print(f"Stav: {row['qb_state']}")
|
||||
print(f"Pokrok: {progress_pct:.2f}%")
|
||||
print(f"Velikost: {row['size_pretty']}")
|
||||
print("-" * 40)
|
||||
|
||||
except pymysql.MySQLError as e:
|
||||
print(f"Chyba při komunikaci s DB: {e}")
|
||||
|
||||
finally:
|
||||
if 'connection' in locals():
|
||||
connection.close()
|
||||
print("Spojení s databází bylo uzavřeno.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_unfinished_torrents()
|
||||
Reference in New Issue
Block a user