commit a4facac7b0658b61dac19eee3f7b1541cf4679d6
parent 3a5ac2a48fcd179b8f5c3929205a25d3928d9554
Author: pyratebeard <root@pyratebeard.net>
Date: Thu, 29 Sep 2022 22:51:05 +0100
query gcd database and output using prettytable
Diffstat:
M | longbox | | | 58 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 58 insertions(+), 0 deletions(-)
diff --git a/longbox b/longbox
@@ -11,6 +11,10 @@
#░ imports
import os
import argparse
+import re
+from getpass import getpass
+from mysql.connector import connect, Error
+from prettytable import PrettyTable
#░ local database dir
def get_db_dir():
@@ -159,3 +163,57 @@ else:
AND gcd_issue.series_id = gcd_series.id
GROUP BY gcd_issue.number
"""
+
+#░ query gcd database
+try:
+ with connect(
+ host="localhost",
+ user=input("username: "),
+ password=getpass("password: "),
+ database="gcd"
+ ) as connection:
+ with connection.cursor() as cursor:
+ if issue_id:
+ x.field_names = ['id','series','issue','variant','year','series_id','issue date','barcode']
+ cursor.execute(show_issue, (issue_id,))
+ for issue in cursor.fetchall():
+ x.add_row(issue)
+ print(x)
+ elif series_id:
+ x.field_names = ['id','series','issue','variant','year','issue date','barcode']
+ cursor.execute(show_series, (series_id,))
+ for issue in cursor.fetchall():
+ x.add_row(issue)
+ x.sortby = "id"
+ print(x)
+ elif search_number:
+ x.field_names = ['id','series','issue','variant','year','series_id','issue date','barcode']
+ if search_date is None:
+ cursor.execute(search_terms, {'search_series': search_series, 'search_number': search_number, 'search_number': search_number, 'search_began': 9999 , 'search_ended': 0 })
+ for issue in cursor.fetchall():
+ x.add_row(issue)
+ print(x.get_string(sort_key=operator.itemgetter(2, 0), sortby="series"))
+ else:
+ cursor.execute(search_terms, {'search_series': search_series, 'search_number': search_number, 'search_number': search_number, 'search_began': search_date, 'search_ended': search_date,})
+ for issue in cursor.fetchall():
+ x.add_row(issue)
+ print(x.get_string(sort_key=operator.itemgetter(2, 0), sortby="series"))
+ elif search_date:
+ x.field_names = ['id','series','year','first issue', 'last issue']
+ print(search_date)
+ cursor.execute(search_terms, {'search_series': search_series, 'search_number': search_number, 'search_number': search_number, 'search_began': search_date, 'search_ended': search_date,})
+ for issue in cursor.fetchall():
+ x.add_row(issue)
+ print(x.get_string(sort_key=operator.itemgetter(2, 0), sortby="year"))
+ elif search_series:
+ x.field_names = ['id','series','year','first issue', 'last issue']
+ cursor.execute(search_terms, (search_series,))
+ for issue in cursor.fetchall():
+ x.add_row(issue)
+ x.sortby = "year"
+ print(x)
+ else:
+ parser.print_help()
+ os._exit(0)
+except Error as e:
+ print(e)