Skip to content

Instantly share code, notes, and snippets.

@troyp
Forked from maforget/CreateCBL.py
Created September 8, 2023 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyp/d4853c42d89771aec49fec6ab7b9220c to your computer and use it in GitHub Desktop.
Save troyp/d4853c42d89771aec49fec6ab7b9220c to your computer and use it in GitHub Desktop.
Create CBL from a Text File
import re;
import os;
with open('sorting.txt') as f:
lines = f.readlines()
with open('template.cbl') as f:
cbl = f.read()
for l in lines:
l = re.sub(r"\..+|\n", "", l, 0, re.IGNORECASE | re.DOTALL)#remove file extension and/or the newline char
filename = 'output/' + l + '.cbl'
os.makedirs(os.path.dirname(filename), exist_ok=True)#Create the output dir if doeasn't exists
newCbl = cbl.replace('Book Name', l)
with open(filename, 'w') as f:
f.write(newCbl)
Test File 001
Test File 002.cbz
Test File 003.cbr
<?xml version="1.0"?>
<ReadingList xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Book Name</Name>
<Books />
<Matchers>
<ComicBookMatcher xsi:type="ComicBookFileMatcher" MatchOperator="3">
<MatchValue>Book Name</MatchValue>
</ComicBookMatcher>
</Matchers>
</ReadingList>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment