Update DataClass.py, StoreXLS.py, and main.py
save to xlsx.. working..now...
This commit is contained in:
@@ -27,9 +27,8 @@ class CBZInfo:
|
||||
|
||||
def RmvArtist(self, name):
|
||||
self.artists.discard(name)
|
||||
|
||||
|
||||
|
||||
|
||||
class TagInfo:
|
||||
def __init__(self, name, url):
|
||||
self.name = name
|
||||
|
||||
178
StoreXLS.py
178
StoreXLS.py
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
from openpyxl import opyxl
|
||||
from openpyxl.utils import xlsUtils
|
||||
import openpyxl as opyxl
|
||||
|
||||
import DataClass as stManga
|
||||
import UtilPack as util
|
||||
@@ -29,30 +28,44 @@ class DBXLStorage:
|
||||
def __exit__(self, ex_type, ex_value, traceback):
|
||||
self.DBXLSClose()
|
||||
|
||||
def DBXLSOpen(self, path):
|
||||
xls_path = self.GetXLSPath(path)
|
||||
def DBXLSOpen(self):
|
||||
print(self.path)
|
||||
xls_path = self.GetXLSPath(self.path)
|
||||
util.DbgOut(xls_path)
|
||||
|
||||
try:
|
||||
m_wb = opyxl(xls_path)
|
||||
self.m_wb = opyxl.load_workbook(xls_path)
|
||||
util.DbgOut("xls Open Successed")
|
||||
except FileNotFoundError:
|
||||
m_wb = opyxl()
|
||||
util.DbgOut("xls Created")
|
||||
self.m_wb = opyxl.Workbook()
|
||||
|
||||
ws = self.m_wb.active
|
||||
ws.title = "DBInfo"
|
||||
ws.cell(row=1,column=1,value="MangaDB_XLS")
|
||||
|
||||
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 m_wb is None:
|
||||
util.DbgOut("XLS Open Something Wrong...")
|
||||
m_openedXLS = ""
|
||||
m_wb = None
|
||||
if self.m_wb is None:
|
||||
util.DbgOut("XLS Open Something Wrong...", True)
|
||||
self.m_openedXLS = ""
|
||||
self.m_wb = None
|
||||
return
|
||||
|
||||
def DBXLSClose(self):
|
||||
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
|
||||
|
||||
self.m_wb.save(self.m_openedXLS)
|
||||
self.m_wb.close()
|
||||
util.DbgOut(f"Close : {self.m_openedXLS} Saved")
|
||||
|
||||
self.m_wb = None
|
||||
|
||||
@@ -69,21 +82,122 @@ class DBXLStorage:
|
||||
# 클래스 타잎을 확인해야 하지만만.. 생략.
|
||||
# ttist, group, series(parady), type, tags, hitomi ID, hitomi file, eh ID, eh tor
|
||||
|
||||
def AddTagInfo(self, tagInfo):
|
||||
pass
|
||||
|
||||
# TAG 정보를 TAG 시트에 추가한다.
|
||||
# 1 , 2 , 3
|
||||
# Index, Tag URL, Tag
|
||||
# 태그는 분류:단어, 이런 식이다.
|
||||
# 분류에는 artist, tag, male, female, other 등이 있다.
|
||||
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
|
||||
|
||||
nSearchID = self.SearchIDFromName(sheetTag, strTag)
|
||||
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
|
||||
|
||||
sheetTag.cell(row=last_row, column=1, value=last_row)
|
||||
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 AddArtistInfo(self, artistInfo):
|
||||
pass
|
||||
|
||||
def AddArAddArtistInfo(self, strArtist, strUrl):
|
||||
pass
|
||||
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):
|
||||
pass
|
||||
|
||||
|
||||
def AddSeriesInfo(self, strSerires, strUrl):
|
||||
pass
|
||||
|
||||
@@ -96,21 +210,27 @@ class DBXLStorage:
|
||||
# 시트를 가져온다. 엑셀 파일이 안 열려 있으면 None, 있으면 반환하고, 없으면 만들어서.
|
||||
def getSheet(self, sheetName):
|
||||
retSheet = None
|
||||
|
||||
if self.m_wb is None:
|
||||
util.DbgOut("XLS not opened", True)
|
||||
return None
|
||||
|
||||
if self.m_wb:
|
||||
if sheetName in self.m_wb.sheetnames:
|
||||
retSheet = self.m_wb[sheetName]
|
||||
else:
|
||||
retSheet = self.m_wb.create_sheet(title=sheetName)
|
||||
try:
|
||||
retSheet = self.m_wb[sheetName]
|
||||
except KeyError:
|
||||
retSheet = self.m_wb.create_sheet(title=sheetName)
|
||||
util.DbgOut(f"GetSheet : {sheetName} is Created", True)
|
||||
|
||||
return retSheet
|
||||
|
||||
# 데이터베이스용 엑셀 파일의 전체 경로를 얻어온다.
|
||||
def GetXLSPath(self, path):
|
||||
retPath = path
|
||||
if False == os.path.exists(path):
|
||||
retPath = os.path.abspath(__file__)
|
||||
retPath = os.path.abspath(path)
|
||||
|
||||
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
10
main.py
@@ -3,17 +3,25 @@ import GetArc_Ehentai as getEhentai
|
||||
import MgrCalibreLibs as mgrCal
|
||||
|
||||
import UtilPack as util
|
||||
import StoreXLS as xls
|
||||
|
||||
def main():
|
||||
#getHitomi.GetSearchResult("2890685")
|
||||
#etEhentai.GetSearchResult("artist%3A%22kotomi+yo-ji%24%22")
|
||||
|
||||
mgrCal.Start()
|
||||
#mgrCal.Start()
|
||||
#util.printDbgMessages()
|
||||
|
||||
#artist:"kotomi yo-ji$"
|
||||
#"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
|
||||
|
||||
Reference in New Issue
Block a user