First commit

This commit is contained in:
MatMasIt 2021-10-03 20:45:58 +02:00 committed by GitHub
parent 9143de7e8b
commit 070acad9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,2 @@
TITLE|The beginning
Oh hello, welcome

42
gen.py Normal file
View File

@ -0,0 +1,42 @@
#!/bin/python3
import glob
import datetime
import functools
def cmp_months(a, b):
a=lastB(a)
b=lastB(b)
lookup={"January":1,"February":2,"March":3,"April":4,"May":5,"June":6,"July":7,"August":8,"September":9,"October":10,"November":11,"Dicember":12}
ca=int(lookup[a])
cb=int(lookup[b])
if ca > cb:
return 1
elif ca == cb:
return 0
else:
return -1
def lastB(path):
e=path.split("/")
return e[len(e)-1]
list=""
years = sorted(glob.glob("diarydata/*"))
for ypath in years:
year = int(lastB(ypath))
list +="\n\\newpage\n\yearH{"+str(year)+"}\n"
for mpath in sorted(glob.glob(ypath+"/*"),key=functools.cmp_to_key(cmp_months)):
month = lastB(mpath)
list +="\n\monthH{"+str(month)+"}\n"
for dpath in sorted(glob.glob(mpath+"/*")):
day = int(lastB(dpath).split(".")[0])
r = datetime.datetime.strptime(str(day)+" "+str(month)+" "+str(year),"%d %B %Y")
fileContent = open(dpath).read().split("\n")
if "TITLE|" in fileContent[0]:
title = fileContent[0].split("|")[1].strip()
s = 1
else:
title = ""
s = 0
list+="\n\dayH{"+r.strftime("%A")+"}{"+str(day)+"}{"+str(title)+"}\n"
for i in range(s,len(fileContent)):
list+=fileContent[i]
modelTex=open("model.tex","r").read()
open("final.tex","w").write(modelTex.replace("REPLACETHIS",list))

43
model.tex Normal file
View File

@ -0,0 +1,43 @@
\documentclass[oneside]{book}
\usepackage{ifthen}\title{\Huge An unremarkable Diary\\\Large of unremarkable things\\ \small By an unremarkable person}
\date{}
\author{Mattia Mascarello}
\usepackage{titlesec}
\usepackage{blindtext}
\titleformat{\chapter}
{\Large\bfseries} % format
{} % label
{0pt} % sep
{\huge}
\newcommand*{\dayOrdinalSuffix}[1]
{
\ifthenelse{\equal{#1}{1}}{st}{
\ifthenelse{\equal{#1}{2}}{nd}{
\ifthenelse{\equal{#1}{3}}{rd}{
\ifthenelse{\equal{#1}{21}}{st}{
\ifthenelse{\equal{#1}{22}}{nd}{
\ifthenelse{\equal{#1}{23}}{rd}{th}
}
}
}
}
}
}
\newcommand*{\justifyheading}{\raggedleft}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % set the \leftmark
\titleformat{\section}{\normalfont\Large\bfseries}{}{0pt}{}
\titleformat{\subsection}{\normalfont\small\bfseries\justifyheading}{}{0pt}{}[{\titlerule[0.8pt]}]
\newcommand{\dayH}[3]{
\subsection{#1 $#2^{\protect\dayOrdinalSuffix{#2}}$}
\begin{flushright}#3\end{flushright}}
\newcommand{\yearH}[1]{\chapter{$#1$}}
\newcommand{\monthH}[1]{\section{#1}}
\begin{document}
\maketitle
\tableofcontents
\chapter{Preamble}
o
\newpage
REPLACETHIS
\end{document}