Skip to content

Instantly share code, notes, and snippets.

Avatar

k5.trismegistus k5trismegistus

View GitHub Profile
@k5trismegistus
k5trismegistus / gist:6fed3f473b8ba98af48c
Created Aug 10, 2014
PythonでComicInfo.xmlを表示
View gist:6fed3f473b8ba98af48c
import zipfile
with zipfile.ZipFile('test.cbz', 'r',) as z:
print(z.read('ComicInfo.xml'))
View ComicInfo.xml
<?xml version="1.0"?>
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Series>sleepless night</Series>
<Year>2008</Year>
<Month>4</Month>
<Day>27</Day>
<Writer>八王子海パン突撃騎兵隊</Writer>
<Penciller>巻田佳春</Penciller>
<Genre>しゅごキャラ!</Genre>
<PageCount>18</PageCount>
@k5trismegistus
k5trismegistus / Roulette
Created Aug 11, 2014
{key, value(数値)}の辞書でルーレット選択
View Roulette
for i in self.pronlist.values():
totalweight += i
r = random.randint(1, totalweight)
for k,v in sorted(self.pronlist.items(), key=lambda x:x[1], reverse=True):
if r <= v:
pron = k
break
else:
r -= v
@k5trismegistus
k5trismegistus / ComicInfoGetter.py
Last active Aug 29, 2015
ウィンドウにドラッグアンドドロップでファイルパスを取得できる
View ComicInfoGetter.py
import wx
import os
class ComicInfoGetter(wx.App):
def OnInit(self):
frm = GuiWindow("ComicInfo Getter from D&M Lexicon")
frm.Show()
return 1
@k5trismegistus
k5trismegistus / ComicInfo.xml
Created Aug 12, 2014
複数のWriter、Pencillerが設定されている場合
View ComicInfo.xml
<?xml version="1.0"?>
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Series>いけない蒼星石</Series>
<Year>2007</Year>
<Month>11</Month>
<Day>25</Day>
<Writer>真・聖堂☆本舗, 東*南*東</Writer>
<Penciller>聖☆司, 米</Penciller>
<Genre>ローゼンメイデン</Genre>
<PageCount>34</PageCount>
@k5trismegistus
k5trismegistus / ComicInfo.xml
Created Aug 12, 2014
Series、Number、Titleがすべて設定されている例
View ComicInfo.xml
<?xml version="1.0"?>
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Title>ACT.1 HARUKA</Title>
<Series>SISTERS 隠された記憶</Series>
<Number>1</Number>
<Year>2011</Year>
<Month>8</Month>
<Writer>マキノ事務所</Writer>
<Genre>SISTERS</Genre>
<PageCount>20</PageCount>
@k5trismegistus
k5trismegistus / Display ComicInfo.xml
Created Aug 12, 2014
ComicInfo.xmlの情報を取得
View Display ComicInfo.xml
import zipfile
import xml.etree.ElementTree as etree
class ComicInfoXmlHandler():
def __init__(self):
self.series = ''
self.number = ''
self.title = ''
View generate_xml
def generate_xml(self, toxml):
g = io.StringIO()
for i in toxml:
if (toxml[i] != '') & (self.root.find(i) is not None):
self.root.find(i).text = toxml[i]
elif (toxml[i] != '') & (self.root.find(i) is None):
newelem = etree.Element(i)
newelem.text = toxml[i]
self.root.find('ComicInfo').append(newelem) ←このへんはまだ試行錯誤中。動かない。
elif toxml[i] == '':
View write_info
def write_info(self, xml2write, filepath): ←xml2writeが渡されるStringIOオブジェクト
with zipfile.ZipFile(filepath, mode='w',) as z:
z.writestr('ComicInfo.xml', xml2write.getvalue())
@k5trismegistus
k5trismegistus / badxml
Last active Aug 29, 2015
ComicInfo.xmlダメな例
View badxml
<?xml version="1.0"?>
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Series>sleepless night</Series>
<Year>2008</Year>
<Day>27</Day>
<Manga>YesAndRightToLeft</Manga>
<Writer>八王子海パン突撃騎兵隊</Writer>
<Month>4</Month>
<Penciller>巻田佳春</Penciller>
<PageCount>18</PageCount>