Update .gitignore, DataClass.py, and 19 more files...
오랜만에 서버 정리하고 커밋. 파일 위치를 정리했다. 캘리버 DB 를 열고 정보를 열람. Pupil 을 통해 다운받은 정보를 관리하기 위해 새로운 클래스 추가
This commit is contained in:
190
DataClass_Pupil.py
Normal file
190
DataClass_Pupil.py
Normal file
@@ -0,0 +1,190 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import UtilPack as util
|
||||
import DataClass as info
|
||||
|
||||
GALBLOCK = "galleryBlock"
|
||||
GALURL = "galleryUrl"
|
||||
GALINFO = "galleryInfo"
|
||||
GALTAGS = "relatedTags"
|
||||
JTITLE = "japanese_title"
|
||||
|
||||
# Example
|
||||
#with open('test.db', 'r') as file:
|
||||
# data = json.load(file)
|
||||
#print_json_tree(data)
|
||||
#print(data['galleryInfo']['tags'])
|
||||
|
||||
# pupil : Json
|
||||
# Caribre : text
|
||||
# Me : CSV
|
||||
class PupilData:
|
||||
m_data = None
|
||||
|
||||
def __init__(self, argv):
|
||||
self.argv = argv
|
||||
self.PupilJSONOpen(argv)
|
||||
|
||||
def __enter__(self):
|
||||
pass
|
||||
|
||||
def __exit__(self, ex_type, ex_value, traceback):
|
||||
pass
|
||||
|
||||
def PupilJSONOpen(self, path:str) -> None:
|
||||
self.m_data = None
|
||||
|
||||
if True == util.IsEmptyStr(path):
|
||||
util.DbgOut("PupilData: input Null", True)
|
||||
return
|
||||
|
||||
if False == os.path.exists(path):
|
||||
return
|
||||
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as file:
|
||||
self.m_data = json.load(file)
|
||||
except FileNotFoundError:
|
||||
util.DbgOut(f"파일이 존재하지 않음: {path}", True)
|
||||
except json.JSONDecodeError:
|
||||
util.DbgOut(f"JSON 형식이 잘못됨: {path}", True)
|
||||
except Exception as e:
|
||||
util.DbgOut(f"기타 오류 발생: {e}", True)
|
||||
|
||||
# pupil 의 JSON 을 파싱해서 DataClass 에 데이터를 넣어 반환한다.
|
||||
"""
|
||||
def GetGalleryBlock(self):
|
||||
['galleryBlock']
|
||||
['id']
|
||||
["galleryUrl"]
|
||||
["thumbnails"]
|
||||
["title"]
|
||||
["artists"]
|
||||
["series"]
|
||||
["type"]
|
||||
["language"]
|
||||
["relatedTags"]
|
||||
["tag"]
|
||||
["url"]
|
||||
["female"]
|
||||
["male"]
|
||||
["groups"]
|
||||
|
||||
def GetGalleryInfo(self):
|
||||
["galleryInfo"]
|
||||
["id"]
|
||||
["title"]
|
||||
["language"]
|
||||
["type"]
|
||||
["date"]
|
||||
["artists"]
|
||||
["artist"]
|
||||
["url"]
|
||||
["groups"]
|
||||
["group"]
|
||||
["url"]
|
||||
["parodys"]
|
||||
["parody"]
|
||||
["url"]
|
||||
["tags"]
|
||||
["tag"]
|
||||
["url"]
|
||||
["female"]
|
||||
["male"]
|
||||
["related"]
|
||||
["languages"]
|
||||
["galleryid"]
|
||||
["url"]
|
||||
["language_localname"]
|
||||
["name"]
|
||||
["characters"]
|
||||
["character"]
|
||||
["url"]
|
||||
["files"]
|
||||
["width"]
|
||||
["hash"]
|
||||
["name"]
|
||||
["height"]
|
||||
["hasavif"]
|
||||
|
||||
def GetInfo(self):
|
||||
if None == self.m_data:
|
||||
return
|
||||
|
||||
title = self.m_data[GALINFO]["title"]
|
||||
url = self.m_data[GALBLOCK]["galleryUrl"]
|
||||
|
||||
retInfo = info(title, url)
|
||||
retInfo.type = self.m_data[GALINFO]["type"]
|
||||
retInfo.language = self.m_data[GALINFO]["language"]
|
||||
retInfo.gallery_id = self.m_data[GALINFO]["id"]
|
||||
|
||||
listArtists = self.m_data[GALINFO]["artists"]
|
||||
for item in listArtists:
|
||||
strArtist = item["artist"]
|
||||
strUrl = item["url"]
|
||||
strTag = f"artist:{strArtist}"
|
||||
|
||||
tempInfo = util.TagInfo(strTag, strUrl)
|
||||
retInfo.AddArtist(tempInfo)
|
||||
|
||||
listTags = self.m_data[GALINFO]["tags"]
|
||||
for item in listTags:
|
||||
strGend = ""
|
||||
if 1 == item["female"]:
|
||||
strGend = "female:"
|
||||
elif 1 == item["male"]:
|
||||
strGend = "male:"
|
||||
|
||||
strTag = item["tag"]
|
||||
strRelatedTag = f"{strGend}:{strTag}"
|
||||
|
||||
tagUrl = item[url]
|
||||
|
||||
tempInfo = util.TagInfo(strRelatedTag, tagUrl)
|
||||
retInfo.AddTag(tempInfo)
|
||||
|
||||
return retInfo
|
||||
"""
|
||||
|
||||
#
|
||||
def GetTitle(self) -> str:
|
||||
retStr : str = ""
|
||||
if None != self.m_data:
|
||||
retStr = self.m_data[GALINFO]["title"]
|
||||
|
||||
return retStr
|
||||
|
||||
#
|
||||
def GetHitomiID(self) -> str:
|
||||
retStr : str = ""
|
||||
if None != self.m_data:
|
||||
retStr = self.m_data[GALINFO]["id"]
|
||||
|
||||
return retStr
|
||||
|
||||
#
|
||||
def GetImgFileCount(self) -> int:
|
||||
if None == self.m_data:
|
||||
return 0
|
||||
|
||||
return len(self.m_data[GALINFO]["files"])
|
||||
|
||||
# pupil 의 JSON 을 파싱해서 ImageFileList 를 반환한다.
|
||||
def GetImgFileList(self):
|
||||
if None == self.m_data:
|
||||
return None
|
||||
|
||||
listRet = set()
|
||||
listFiles = self.m_data[GALINFO]["files"]
|
||||
for item in listFiles:
|
||||
tempInfo = info.ImageFileInfo(item["name"],
|
||||
item["height"],
|
||||
item["width"],
|
||||
item["hash"],
|
||||
item["haswebp"])
|
||||
listRet.append(tempInfo)
|
||||
|
||||
return listRet
|
||||
|
||||
Reference in New Issue
Block a user