diff --git a/diarydata/2021/October/03.tex b/diarydata/2021/October/03.tex new file mode 100644 index 0000000..2ffb909 --- /dev/null +++ b/diarydata/2021/October/03.tex @@ -0,0 +1,2 @@ +TITLE|The beginning +Oh hello, welcome diff --git a/gen.py b/gen.py new file mode 100644 index 0000000..78ec5ee --- /dev/null +++ b/gen.py @@ -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)) diff --git a/model.tex b/model.tex new file mode 100644 index 0000000..dea23d0 --- /dev/null +++ b/model.tex @@ -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}