You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
282 lines
6.4 KiB
282 lines
6.4 KiB
#!/usr/bin/python3
|
|
|
|
import math
|
|
|
|
from datetime import timedelta
|
|
from PyPDF2 import PdfFileReader
|
|
from datetime import date
|
|
import locale
|
|
import os
|
|
|
|
# local imports
|
|
from yearly_view import tex_write_year_overview
|
|
|
|
|
|
start_year = 2022
|
|
|
|
main_filename = "calender"
|
|
main_tex = main_filename + ".tex"
|
|
main_aux = main_filename + ".aux"
|
|
main_log = main_filename + ".log"
|
|
main_pdf = main_filename + ".pdf"
|
|
|
|
combine_filename = "combine"
|
|
combine_tex = combine_filename + ".tex"
|
|
combine_aux = combine_filename + ".aux"
|
|
combine_log = combine_filename + ".log"
|
|
combine_pdf = combine_filename + ".pdf"
|
|
|
|
combine2_filename = "combine2"
|
|
combine2_tex = combine2_filename + ".tex"
|
|
combine2_aux = combine2_filename + ".aux"
|
|
combine2_log = combine2_filename + ".log"
|
|
combine2_pdf = combine2_filename + ".pdf"
|
|
|
|
color_saturday = "orange"
|
|
color_sunday = "red"
|
|
color_weekday = "black"
|
|
color_lines = "black"
|
|
|
|
|
|
|
|
def main():
|
|
# german
|
|
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
|
|
|
|
fd = open(main_tex, "w")
|
|
tex_write_header(fd)
|
|
|
|
tex_write_year_overview(fd,start_year)
|
|
|
|
tex_write_weekly(fd)
|
|
|
|
tex_write_footer(fd)
|
|
|
|
fd.close()
|
|
|
|
cmd = 'pdflatex ' + main_tex
|
|
|
|
os.system(cmd)
|
|
os.remove(main_aux)
|
|
os.remove(main_log)
|
|
|
|
|
|
def tex_write_header(fd):
|
|
# \usepackage{fontspec}{}
|
|
fd.write('''
|
|
\\documentclass[12pt,twoside]{scrartcl}
|
|
%%%%%%%%
|
|
%
|
|
% Latex-Vorlage fuer einen eigenen Wochenkalender
|
|
% Author Philipp Schoenberger
|
|
|
|
\\usepackage[german, english]{babel}
|
|
\\usepackage[labelformat=empty]{caption}
|
|
\\usepackage{mathtools}
|
|
\\usepackage{xcolor}
|
|
\\usepackage{textcomp}
|
|
\\usepackage{marvosym}
|
|
\\usepackage[clock]{ifsym}
|
|
\\usepackage{geometry}
|
|
\\geometry{
|
|
a5paper,
|
|
left=10mm,
|
|
top=10mm,
|
|
}
|
|
|
|
\\newcommand\\myhrulefill[2][0pt]{\\leavevmode\\leaders\\hrule height #2 depth #1\\hfill\\kern0pt}
|
|
|
|
|
|
\\begin{document}{}
|
|
''')
|
|
|
|
|
|
def tex_write_footer(fd):
|
|
fd.write('''
|
|
\\ \\newpage
|
|
\\ \\newpage
|
|
\\end{document}
|
|
''')
|
|
|
|
|
|
def tex_write_weekly(fd):
|
|
start_date = date(start_year, 1, 1)
|
|
end_date = date(start_year, 12, 31)
|
|
print_start_date = start_date - timedelta(days=start_date.weekday())
|
|
print_end_date = end_date + timedelta(days=6 - end_date.weekday())
|
|
|
|
print(print_start_date.isoformat())
|
|
print(print_end_date.isoformat())
|
|
|
|
fd.write('''
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
% begin real calender
|
|
\\flushleft
|
|
''')
|
|
|
|
curr_date = print_start_date - timedelta(days=1)
|
|
|
|
while True:
|
|
next_date = curr_date + timedelta(days=1)
|
|
if (print_end_date == next_date):
|
|
break
|
|
curr_date = next_date
|
|
|
|
if curr_date.weekday() == 0:
|
|
fd.write('' + curr_date.strftime('%B'))
|
|
last_weekday = curr_date + timedelta(days=6)
|
|
fd.write('~' + curr_date.strftime('%Y'))
|
|
|
|
if (curr_date.month != last_weekday.month):
|
|
fd.write(' $-$')
|
|
fd.write('~' + last_weekday.strftime('%Y'))
|
|
fd.write('\\hrule')
|
|
|
|
if curr_date.weekday() == 5:
|
|
fd.write('\\color{' + color_saturday + '}')
|
|
elif curr_date.weekday() == 6:
|
|
fd.write('\\color{' + color_sunday + '}')
|
|
else:
|
|
fd.write('\\color{' + color_weekday + '}')
|
|
|
|
fd.write('''
|
|
\\parbox[t][0.115\\paperheight]{\\textwidth}{
|
|
\\flushleft
|
|
\\textbf{
|
|
\\small ''')
|
|
fd.write('' + curr_date.strftime('%d'))
|
|
fd.write(' - ')
|
|
fd.write('' + curr_date.strftime('%A'))
|
|
fd.write('''
|
|
}
|
|
\\hspace{5mm}~
|
|
\\myhrulefill{0.5pt}
|
|
\\linebreak
|
|
\\noindent
|
|
\\begin{minipage}[t][2.3cm]{0.48\\textwidth}
|
|
\\hspace*{1.2cm} ~
|
|
\\end{minipage}
|
|
\\begin{minipage}[t][6.1cm]{0.48\\textwidth}
|
|
\\begin{flushright}
|
|
~
|
|
\\end{flushright}
|
|
\\end{minipage}
|
|
}
|
|
''')
|
|
|
|
# start new page if sunday
|
|
if curr_date.weekday() == 6:
|
|
fd.write('\\newpage\n\r')
|
|
fd.write('\\color{' + color_lines + '}')
|
|
for i in range(1, 18):
|
|
fd.write('\\hspace{8mm}\n\r')
|
|
fd.write('\\myhrulefill{0.5pt}\n\r')
|
|
fd.write('\\newpage\n\r')
|
|
|
|
fd.write('''
|
|
% end real calender
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
''')
|
|
|
|
|
|
def gen_page_include(page1, page2, filename, maxpages, nup):
|
|
s = "{"
|
|
if page1 < maxpages:
|
|
s += str(page1)
|
|
else:
|
|
s += str(maxpages)
|
|
s += ","
|
|
|
|
if page2 < maxpages:
|
|
s += str(page2)
|
|
else:
|
|
s += str(maxpages)
|
|
s += "}"
|
|
|
|
return "\\includepdf[pages=" + s + ", nup=" + nup + "]{" + filename + "}\n"
|
|
|
|
|
|
def combine_a7():
|
|
pdf = PdfFileReader(open(main_pdf, 'rb'))
|
|
|
|
fd = open(combine_tex, "w")
|
|
fd.write("""
|
|
\\documentclass{article}
|
|
\\usepackage{pdfpages} % for \\includepdf[pages=-]
|
|
|
|
\\begin{document}
|
|
""")
|
|
|
|
# last page is empty
|
|
pdf_number = pdf.getNumPages()
|
|
|
|
seq = pdf_number
|
|
seq = float(seq) / float(2)
|
|
seq = math.ceil(seq)
|
|
seq = float(seq) / float(2)
|
|
seq = math.ceil(seq)
|
|
seq = int(seq)
|
|
|
|
for i in range(1, seq + 1):
|
|
fd.write(gen_page_include(seq * 4 - (2 * i - 1), 2 * i - 1, main_pdf, pdf_number, "1x2,landscape=true"))
|
|
fd.write(gen_page_include(2 * i, seq * 4 - (2 * i), main_pdf, pdf_number, "1x2,landscape=true"))
|
|
|
|
fd.write("""
|
|
\\end{document}
|
|
""")
|
|
|
|
fd.close()
|
|
cmd = 'pdflatex ' + combine_tex
|
|
|
|
os.system(cmd)
|
|
# os.remove(combine_aux)
|
|
# os.remove(combine_log)
|
|
|
|
print(seq)
|
|
print(seq * 4)
|
|
|
|
# now combine even aggain to get a6
|
|
|
|
pdf = PdfFileReader(open(combine_pdf, 'rb'))
|
|
|
|
fd = open(combine2_tex, "w")
|
|
fd.write("""
|
|
\\documentclass{article}
|
|
\\usepackage{pdfpages} % for \\includepdf[pages=-]
|
|
|
|
\\begin{document}
|
|
""")
|
|
|
|
# # last page is empty
|
|
pdf_number = pdf.getNumPages()
|
|
|
|
seq = pdf_number
|
|
seq = float(seq) / float(2)
|
|
seq = math.ceil(seq)
|
|
seq = float(seq) / float(2)
|
|
seq = math.ceil(seq)
|
|
seq = int(seq)
|
|
|
|
for i in range(1, seq + 1):
|
|
fd.write(gen_page_include(i * 4 - 3, i * 4 - 1, combine_pdf, pdf_number, "1x2,landscape=false"))
|
|
fd.write(gen_page_include(i * 4 - 2, i * 4, combine_pdf, pdf_number, "1x2,landscape=false"))
|
|
|
|
fd.write("""
|
|
\\end{document}
|
|
""")
|
|
|
|
fd.close()
|
|
cmd = 'pdflatex ' + combine2_tex
|
|
|
|
os.system(cmd)
|
|
# os.remove(combine2_aux)
|
|
# os.remove(combine2_log)
|
|
|
|
print(seq)
|
|
print(seq * 4)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
combine_a7()
|