commit fcc3d39fb3ec7eedb3f102e78735cd51b526d5ea
parent 3961a5ccbed81f55137a8935bcdc243c552f7143
Author: pyratebeard <root@pyratebeard.net>
Date: Thu, 29 Sep 2022 22:55:10 +0100
manage local stash
create and show categories. insert issue into stash
Diffstat:
M | longbox | | | 178 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- |
1 file changed, 130 insertions(+), 48 deletions(-)
diff --git a/longbox b/longbox
@@ -15,6 +15,9 @@ import re
from getpass import getpass
from mysql.connector import connect, Error
from prettytable import PrettyTable
+import sqlite3
+from sqlite3 import Error
+import operator
#░ local database dir
def get_db_dir():
@@ -208,60 +211,139 @@ if stash:
);
""".format(stash_category)
+def stash_connection(db_file):
+ conn = none
+ try:
+ conn = sqlite3.connect(db_file)
+ stashcursor = conn.cursor()
+ if stash_issue_id:
+ try:
+ with connect(
+ host="localhost",
+ user=input("username: "),
+ password=getpass("password: "),
+ database="gcd"
+ ) as connection:
+ with connection.cursor() as cursor:
+ cursor.execute(show_issue, (stash_issue_id,))
+ for issue in cursor.fetchall():
+ gcd_issue_id = issue[0]
+ gcd_series_name = issue[1]
+ gcd_issue_number = issue[2]
+ gcd_variant_name = issue[3]
+ gcd_series_year = issue[4]
+ gcd_series_id = issue[5]
+ gcd_issue_date = issue[6]
+ gcd_barcode = issue[7]
+ except error as e:
+ print(e)
+
+ stashcursor.execute(stash_create_table, {'category': stash_category,})
+
+ stash_issue_tuple = (gcd_issue_id, gcd_series_name, gcd_issue_number, gcd_variant_name, gcd_series_year, gcd_series_id, gcd_issue_date, gcd_barcode)
+ stashcursor.execute('select * from ' + stash_category + ' where stash_issue_id='+stash_issue_id)
+ entry = stashcursor.fetchone()
+
+ if entry is none:
+ stashcursor.execute(stash_issue, stash_issue_tuple)
+ conn.commit()
+ else:
+ print('already stashed')
+ os._exit(0)
+
+ x.field_names = ['id','series','issue','variant','year','series_id','issue date','barcode']
+ stashcursor.execute(stash_show_category)
+ for stashedissue in stashcursor.fetchall():
+ x.add_row(stashedissue)
+ print(x.get_string(sort_key=operator.itemgetter(2, 0), sortby="series"))
+
+ elif stash_category != 'unsorted':
+ stashcursor.execute(stash_create_table, {'category': stash_category,})
+ x.field_names = ['id','series','issue','variant','year','series_id','issue date','barcode']
+ stashcursor.execute(stash_show_category)
+ for stashedissue in stashcursor.fetchall():
+ x.add_row(stashedissue)
+ print(x.get_string(sort_key=operator.itemgetter(2, 0), sortby="series"))
+
+ else:
+ # can we get rowcount?
+ x.field_names = ['category', 'quantity']
+ stashcursor.execute(stash_show_tables)
+ for stashcategory in stashcursor.fetchall():
+ str = ''
+ for item in stashcategory:
+ str = str + item
+ category_quantity = stashcursor.execute("select * from " + str)
+ stashcategory_quantity = len(category_quantity.fetchall())
+ stash_list = [str, stashcategory_quantity]
+ x.add_row(stash_list)
+ x.sortby = "category"
+ print(x)
+
+ except error as e:
+ print(e)
+ finally:
+ if conn:
+ conn.close()
+
#░ prettytable short var
x = PrettyTable()
x.align = "l"
-#░ 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 })
+#░ manage stash
+if stash:
+ stash_connection(boxdb)
+else:
+ #░ 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.get_string(sort_key=operator.itemgetter(2, 0), sortby="series"))
- else:
+ 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="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)
+ 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)