Update DataClass.py, StoreXLS.py, and main.py

save to xlsx.. working..now...
This commit is contained in:
2024-05-31 20:51:12 +09:00
parent d4bc88e9b4
commit 72896d3ddf
3 changed files with 159 additions and 32 deletions

View File

@@ -29,7 +29,6 @@ class CBZInfo:
self.artists.discard(name) self.artists.discard(name)
class TagInfo: class TagInfo:
def __init__(self, name, url): def __init__(self, name, url):
self.name = name self.name = name

View File

@@ -1,6 +1,5 @@
import os import os
from openpyxl import opyxl import openpyxl as opyxl
from openpyxl.utils import xlsUtils
import DataClass as stManga import DataClass as stManga
import UtilPack as util import UtilPack as util
@@ -29,30 +28,44 @@ class DBXLStorage:
def __exit__(self, ex_type, ex_value, traceback): def __exit__(self, ex_type, ex_value, traceback):
self.DBXLSClose() self.DBXLSClose()
def DBXLSOpen(self, path): def DBXLSOpen(self):
xls_path = self.GetXLSPath(path) print(self.path)
xls_path = self.GetXLSPath(self.path)
util.DbgOut(xls_path) util.DbgOut(xls_path)
try: try:
m_wb = opyxl(xls_path) self.m_wb = opyxl.load_workbook(xls_path)
util.DbgOut("xls Open Successed") util.DbgOut("xls Open Successed")
except FileNotFoundError: except FileNotFoundError:
m_wb = opyxl() self.m_wb = opyxl.Workbook()
util.DbgOut("xls Created")
if m_wb is None: ws = self.m_wb.active
util.DbgOut("XLS Open Something Wrong...") ws.title = "DBInfo"
m_openedXLS = "" ws.cell(row=1,column=1,value="MangaDB_XLS")
m_wb = None
self.m_wb.create_sheet(self.strMngSht)
self.m_wb.create_sheet(self.strArtSht)
self.m_wb.create_sheet(self.strTagSht)
self.m_wb.save(xls_path)
util.DbgOut(f"{xls_path} Created", True)
self.m_openedXLS = xls_path
if self.m_wb is None:
util.DbgOut("XLS Open Something Wrong...", True)
self.m_openedXLS = ""
self.m_wb = None
return return
def DBXLSClose(self): def DBXLSClose(self):
if self.m_wb is None or self.m_openedXLS is None: if self.m_wb is None or self.m_openedXLS is None:
util.DbgOut("XLS Close something wrong...") util.DbgOut("XLS Close something wrong...", True)
return return
self.m_wb.save(self.m_openedXLS) self.m_wb.save(self.m_openedXLS)
self.m_wb.close() self.m_wb.close()
util.DbgOut(f"Close : {self.m_openedXLS} Saved")
self.m_wb = None self.m_wb = None
@@ -69,21 +82,122 @@ class DBXLStorage:
# 클래스 타잎을 확인해야 하지만만.. 생략. # 클래스 타잎을 확인해야 하지만만.. 생략.
# ttist, group, series(parady), type, tags, hitomi ID, hitomi file, eh ID, eh tor # ttist, group, series(parady), type, tags, hitomi ID, hitomi file, eh ID, eh tor
def AddTagInfo(self, tagInfo): # TAG 정보를 TAG 시트에 추가한다.
pass # 1 , 2 , 3
# Index, Tag URL, Tag
# 태그는 분류:단어, 이런 식이다.
# 분류에는 artist, tag, male, female, other 등이 있다.
def AddTagInfo(self, strTag, strUrl): def AddTagInfo(self, strTag, strUrl):
pass sheetTag = self.getSheet(self.strTagSht)
if sheetTag is None:
util.DbgOut(f"AddTag : {self.strTagSht} Get Failed...", True)
return
def AddArtistInfo(self, artistInfo): nSearchID = self.SearchIDFromName(sheetTag, strTag)
pass if 0 > nSearchID:
util.DbgOut(f"AddTag : {self.strTagSht} Get Failed...", True)
elif 0 < nSearchID:
util.DbgOut(f"AddTag : {self.strTagSht}:{nSearchID},{strTag} is exist.")
else:
last_row = sheetTag.max_row
if sheetTag.cell(row=last_row, column=1).value :
last_row += 1
def AddArAddArtistInfo(self, strArtist, strUrl): sheetTag.cell(row=last_row, column=1, value=last_row)
pass sheetTag.cell(row=last_row, column=2, value=strUrl)
sheetTag.cell(row=last_row, column=3, value=strTag)
util.DbgOut(f"AddTag : {self.strTagSht}:{nSearchID},{strTag} added.")
def SearchIDFromName(self, sheet, strValue, nTrgCol=3):
if sheet is None :
return -1
nRetID = 0
for nRow in range(1, sheet.max_row + 1):
valTemp = sheet.cell(row=nRow, column=nTrgCol).value
if None == valTemp :
continue
if valTemp.casefold() == strValue.casefold() :
nRetID = sheet.cell(row=nRow, column=1).value
break;
return nRetID
# 같은 값을 가지고 있는 ROW, 혹은 index 를 반
def SearchIDFromList(self, sheet, listValue, nStartCol=3):
if sheet is None :
return -1
nRetID = 0
for nRow in range(1, sheet.max_row + 1):
for nCol in range(0, len(listValue)):
valTemp = sheet.cell(row=nRow, column=nStartCol + nCol).value
if None == valTemp :
continue
strValue = listValue[nCol]
if valTemp.casefold() == strValue.casefold() :
nRetID = sheet.cell(row=nRow, column=1).value
break;
return nRetID
def AddArtistInfo(self, ArtName, strUrl):
shtArt = self.getSheet(self.strArtSht)
if shtArt is None:
util.DbgOut(f"AddArtist : {self.strArtSht} Get Failed...", True)
return
# ArtName 이 리스트인 경우, String 인 경우로 구분한다. 그 외는 몰라.
if isinstance(ArtName, str):
nSearchID = self.SearchIDFromName(shtArt, ArtName)
if 0 > nSearchID:
util.DbgOut(f"AddArtist : {self.sheetArtist} Get Failed...", True)
elif 0 < nSearchID:
util.DbgOut(f"AddArtist : {self.sheetArtist}:{nSearchID},{strTag} is exist.")
else:
last_row = sheetTag.max_row
if sheetArtist.cell(row=last_row, column=1).value :
last_row += 1
sheetArtist.cell(row=last_row, column=1, value=last_row)
sheetArtist.cell(row=last_row, column=2, value=strUrl)
sheetArtist.cell(row=last_row, column=3, value=strArt)
elif isinstance(ArtName, list):
nSearchID = self.SearchIDFromName(shtArt, ArtName)
if 0 > nSearchID:
util.DbgOut(f"AddArtist : {self.sheetArtist} Get Failed...", True)
elif 0 < nSearchID:
util.DbgOut(f"AddArtist : {self.sheetArtist}:{nSearchID},{strTag} is exist.")
else:
last_row = sheetTag.max_row
if sheetArtist.cell(row=last_row, column=1).value :
last_row += 1
sheetArtist.cell(row=last_row, column=1, value=last_row)
sheetArtist.cell(row=last_row, column=2, value=strUrl)
strDebugParam = ""
nCol = 3
if isinstance(ArtName, str):
sheetArtist.cell(row=last_row, column=nCol, value=strArt)
strDebugParam = ArtName
elif isinstance(ArtName, list):
for strArt in listArtist:
sheetArtist.cell(row=last_row, column=nCol, value=strArt)
nCol += 1
util.DbgOut(f"AddArtist : {self.sheetArtist}:{last_row},{strDebugParam} added.")
def AddSeriesInfo(self, SeriesInfo): def AddSeriesInfo(self, SeriesInfo):
pass pass
def AddSeriesInfo(self, strSerires, strUrl): def AddSeriesInfo(self, strSerires, strUrl):
pass pass
@@ -97,20 +211,26 @@ class DBXLStorage:
def getSheet(self, sheetName): def getSheet(self, sheetName):
retSheet = None retSheet = None
if self.m_wb: if self.m_wb is None:
if sheetName in self.m_wb.sheetnames: util.DbgOut("XLS not opened", True)
return None
try:
retSheet = self.m_wb[sheetName] retSheet = self.m_wb[sheetName]
else: except KeyError:
retSheet = self.m_wb.create_sheet(title=sheetName) retSheet = self.m_wb.create_sheet(title=sheetName)
util.DbgOut(f"GetSheet : {sheetName} is Created", True)
return retSheet return retSheet
# 데이터베이스용 엑셀 파일의 전체 경로를 얻어온다. # 데이터베이스용 엑셀 파일의 전체 경로를 얻어온다.
def GetXLSPath(self, path): def GetXLSPath(self, path):
retPath = path retPath = os.path.abspath(path)
if False == os.path.exists(path):
retPath = os.path.abspath(__file__)
return os.path.join(retPath, self.xls_name) if False == os.path.exists(retPath):
abspath = os.path.dirname(__file__)
retPath = os.path.join(abspath, self.xls_name)
return retPath

10
main.py
View File

@@ -3,17 +3,25 @@ import GetArc_Ehentai as getEhentai
import MgrCalibreLibs as mgrCal import MgrCalibreLibs as mgrCal
import UtilPack as util import UtilPack as util
import StoreXLS as xls
def main(): def main():
#getHitomi.GetSearchResult("2890685") #getHitomi.GetSearchResult("2890685")
#etEhentai.GetSearchResult("artist%3A%22kotomi+yo-ji%24%22") #etEhentai.GetSearchResult("artist%3A%22kotomi+yo-ji%24%22")
mgrCal.Start() #mgrCal.Start()
#util.printDbgMessages() #util.printDbgMessages()
#artist:"kotomi yo-ji$" #artist:"kotomi yo-ji$"
#"artist%3A%22kotomi+yo-ji%24%22" #"artist%3A%22kotomi+yo-ji%24%22"
tempxls = xls.DBXLStorage("./temp.xls")
tempxls.DBXLSOpen()
tempxls.AddTagInfo("female:bondage", "/tag/bondage/")
tempxls.AddTagInfo("female:slave", "/tag/slave/")
tempxls.DBXLSClose()
# For Main Loop # For Main Loop