Añadido zxdb.py

This commit is contained in:
2023-08-12 18:09:47 +02:00
parent 5de6d8cf6c
commit 874ca12fcf
2 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ for opt, arg in opts:
opt_list = "yes"
elif opt in ("-m", "--manufacturer"):
opt_manufacturer = arg
elif opt == '-d':
elif opt in ("-d", "--dat"):
opt_dat = arg
elif opt in ("-c", "--copy"):
opt_copy = "yes"
+39
View File
@@ -0,0 +1,39 @@
import mysql.connector
from mysql.connector import errorcode
config = {
'user': 'root',
'password': 'unJEPimbJddHP8',
'host': '127.0.0.1',
'database': 'zxdb',
'raise_on_warnings': True
}
try:
cnx = mysql.connector.connect(**config)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cursor = cnx.cursor()
query = ("SELECT id, title FROM entries "
"WHERE id BETWEEN %s AND %s")
id_start = 1950
id_end = 1980
cursor.execute(query, (id_start, id_end))
for (id, title) in cursor:
print("{} ({})".format(title, id))
cursor.close()
cnx.close()