commit de9a92ea9e3c4552c0727f44eed2ff9d4e6167d0
parent 3229b9323da306fdbc802f2f729c684a29730356
Author: pyratebeard <root@pyratebeard.net>
Date: Thu, 29 Sep 2022 22:27:22 +0100
tidying up
Diffstat:
M | longbox | | | 169 | +++++-------------------------------------------------------------------------- |
1 file changed, 10 insertions(+), 159 deletions(-)
diff --git a/longbox b/longbox
@@ -7,51 +7,25 @@
# what ░ comic book stash manager
# who ░ pyratebeard <root@pyratebeard.net>
# repo ░ https://git.pyratebeard.net/longbox
-#
-# TODO
-# * create personal stash database
-# * add issues from gcd to stash
-# * easy view stash
-# * web browser
-# * ranger style ncurses
-# * import from csv
-# * search stash
-# * organise
-# * pull list
-# * credentials from variables
-# * fix date search with no issue number
-
-# multiple db connections
-#mydb1 = MySQLdb.connect(host="localhost",
-# user="skipper",
-# passwd="mysecret",
-# db="fish")
-#mydb2 = MySQLdb.connect(host="localhost",
-# user="skipper",
-# passwd="mysecret",
-# db="fruit")
-#cursor1 = mydb1.cursor()
-#cursor2 = mydb2.cursor()
-from getpass import getpass
-from mysql.connector import connect, Error
-import argparse
-from prettytable import PrettyTable
-import re
+#░ imports
import os
+#░ local database dir
def get_db_dir():
data_home = os.environ.get('XDG_DATA_HOME')
if data_home is None:
data_home = os.path.join(os.environ.get('HOME'), '.local', 'share')
return os.path.join(data_home, 'longbox')
+#░ local conf dir
def get_conf_dir():
conf_home = os.environ.get('XDG_CONFIG_HOME')
if conf_home is None:
conf_home = os.path.join(os.environ.get('HOME'), '.config')
return os.path.join(conf_home, 'longbox')
+#░ mkdirs if not exist
def mkdirs(path):
try:
if not os.path.exists(path):
@@ -60,137 +34,14 @@ def mkdirs(path):
print(e)
os._exit(1)
+#░ local database files
+#░ for stash and wishlist
dbpath = get_db_dir()
-boxdb = os.path.join(dbpath, 'longbox.db')
mkdirs(dbpath)
+stashdb = os.path.join(dbpath, 'stash.db')
+wishdb = os.path.join(dbpath, 'wishlist.db')
+#░ local conf file
confpath = get_conf_dir()
-boxrc = os.path.join(confpath, 'longboxrc')
mkdirs(confpath)
-
-# parse arguments
-parser = argparse.ArgumentParser(description = "comic book stash manager")
-parser.add_argument("-q", "--query", help = "search for stuff", required = False, action='store', nargs='+')
-parser.add_argument("-i", "--issue-id", help = "show specific issue id", required = False, default = None)
-parser.add_argument("-s", "--series-id", help = "list all issues in series", required = False, default = None)
-## -g --gcd ; if gcd use gcd db
-## --import
-argument = parser.parse_args()
-
-query = argument.query
-issue_id = argument.issue_id
-series_id = argument.series_id
-
-search_series = '%'
-search_number = None
-search_date = None
-
-if query:
- search_series = query[0]
- if len(query) >= 2:
- numregexp = re.compile(r'^#')
- dateregexp = re.compile(r'^[0-9]')
- for q in query[1:]:
- if numregexp.search(q):
- search_number = q.lstrip('#')
- if dateregexp.search(q):
- search_date = q
-
-if search_number:
- search_terms = """
- SELECT gcd_issue.id,left(gcd_series.name, 50),CONCAT(gcd_series.year_began, '-', coalesce(gcd_series.year_ended, 'unknown')),left(gcd_issue.number, 10),left(gcd_issue.variant_name, 50),gcd_issue.publication_date,right(gcd_issue.barcode, 5)
- FROM gcd_series JOIN gcd_issue
- WHERE gcd_series.name LIKE CONCAT('%', %(search_series)s, '%')
- AND (gcd_issue.number = %(search_number)s OR gcd_issue.number LIKE CONCAT(%(search_number)s, ' (%)'))
- AND gcd_issue.series_id = gcd_series.id
- AND (gcd_series.year_began <= %(search_began)s AND (gcd_series.year_ended >= %(search_ended)s or gcd_series.year_ended is null))
- """
-else:
- if search_date:
- search_terms = """
- SELECT gcd_series.id,left(gcd_series.name, 50),CONCAT(gcd_series.year_began, ' - ', gcd_series.year_ended),first.number,last.number
- FROM gcd_series
- INNER JOIN gcd_issue first
- ON first.id = gcd_series.first_issue_id
- INNER JOIN gcd_issue last
- ON last.id = gcd_series.last_issue_id
- WHERE gcd_series.name LIKE CONCAT('%', %(search_series)s, '%')
- AND (gcd_series.year_began <= %(search_began)s AND (gcd_series.year_ended >= %(search_ended)s or gcd_series.year_ended is null))
- """
- else:
- search_terms = """
- SELECT gcd_series.id,left(gcd_series.name, 50),CONCAT(gcd_series.year_began, ' - ', gcd_series.year_ended),first.number,last.number
- FROM gcd_series
- INNER JOIN gcd_issue first
- ON first.id = gcd_series.first_issue_id
- INNER JOIN gcd_issue last
- ON last.id = gcd_series.last_issue_id
- WHERE gcd_series.name LIKE CONCAT('%', %s, '%')
- """
-
-show_issue = """
-SELECT gcd_issue.id,left(gcd_series.name, 50),CONCAT(gcd_series.year_began, ' - ', gcd_series.year_ended),left(gcd_issue.number, 10),left(gcd_issue.variant_name, 50),gcd_issue.publication_date,right(gcd_issue.barcode, 5)
-FROM gcd_series JOIN gcd_issue
-WHERE gcd_issue.id = %s
-AND gcd_issue.series_id = gcd_series.id
-"""
-
-show_series = """
-SELECT gcd_issue.id,left(gcd_series.name, 50),CONCAT(gcd_series.year_began, ' - ', gcd_series.year_ended),left(gcd_issue.number, 10),left(gcd_issue.variant_name, 50),gcd_issue.publication_date,right(gcd_issue.barcode, 5)
-FROM gcd_series JOIN gcd_issue
-WHERE gcd_issue.series_id = %s
-AND gcd_issue.series_id = gcd_series.id
-"""
-
-x = PrettyTable()
-x.align = "l"
-
-try:
- with connect(
- host="localhost",
- user="gcd",
- password="gcddump",
- #user=input("username: "),
- #password=getpass("password: "),
- database="gcd"
- ) as connection:
- with connection.cursor() as cursor:
- if issue_id:
- x.field_names = ['id','series','year','issue','variant','issue date','barcode']
- cursor.execute(show_issue, (issue_id,))
- for issue in cursor.fetchall():
- x.add_row(issue)
- box_id = issue[0]
- box_series = issue[1]
- box_year = issue[2]
- box_number = issue[3]
- box_variant = issue[4]
- box_date = issue[5]
- box_barcode = issue[6]
- print('id: ', box_id, '\nseries: ', box_series)
- elif series_id:
- x.field_names = ['id','series','year','issue','variant','issue date','barcode']
- cursor.execute(show_series, (series_id,))
- for issue in cursor.fetchall():
- x.add_row(issue)
- elif search_number:
- x.field_names = ['id','series','year','issue','variant','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)
- else:
- 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)
- else:
- 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)
- print(x)
-except Error as e:
- print(e)
-
-
+boxrc = os.path.join(confpath, 'longboxrc')