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.
360 lines
8.6 KiB
360 lines
8.6 KiB
#!/usr/bin/python
|
|
import math
|
|
|
|
from datetime import timedelta
|
|
from datetime import date
|
|
import locale
|
|
import os
|
|
|
|
start_year = 2019
|
|
start_date = date(start_year, 01, 01)
|
|
end_date = date(start_year, 12, 31)
|
|
|
|
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"
|
|
|
|
dates = '''
|
|
{
|
|
"Birthday": [
|
|
{ "date": "1.1.2020", "title": "Philipp1 Schoenberer" },
|
|
{ "date": "3.1.2020", "title": "Philipp3 Schoenberer" },
|
|
{ "date": "5.1.2020", "title": "Philipp5 Schoenberer" },
|
|
}
|
|
'''
|
|
|
|
|
|
def main():
|
|
# german
|
|
locale.setlocale(locale.LC_TIME, "de_DE")
|
|
|
|
fd = open(main_tex, "w")
|
|
tex_write_header(fd)
|
|
|
|
tex_write_calender_overview(fd)
|
|
|
|
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_calender_overview(fd):
|
|
fd.write('''
|
|
|
|
\\thispagestyle{empty}
|
|
\\vspace*{-2em}
|
|
%\\renewcommand{\\arraystretch}{0.9}
|
|
%\\setlength{\\tabcolsep}{0.9mm}
|
|
\\begin{center}
|
|
\\Huge\\textbf{Jahres\\"ubersicht\\ ''')
|
|
fd.write(str(start_year))
|
|
fd.write('''}
|
|
\\end{center}
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
% begin overview calender
|
|
\\renewcommand{\\arraystretch}{1.0}
|
|
\\setlength{\\tabcolsep}{0.9mm}
|
|
''')
|
|
for month in range(1, 12 + 1):
|
|
m = date(start_year, month, 01)
|
|
|
|
if (month - 1) % 2 == 0:
|
|
fd.write('\\ \\newline\n\r')
|
|
|
|
fd.write('''\\begin{minipage}[t]{0.5\\textwidth}
|
|
\\centering
|
|
''')
|
|
fd.write('\\textbf{\\large ' + m.strftime('%B') + '} ')
|
|
fd.write('''\\\\
|
|
\\vspace{3mm}
|
|
\\tiny
|
|
\\begin{tabular}{ccccc|cc||}
|
|
''')
|
|
|
|
# print weeknames
|
|
for i in range(0, 6 + 1):
|
|
curr_date = date(start_year, month, 01)
|
|
curr_date = curr_date + timedelta(days=i - curr_date.weekday())
|
|
|
|
fd.write('\\textbf{' + curr_date.strftime('%a') + '} ')
|
|
if i == 6:
|
|
fd.write('\\\\\n\r')
|
|
else:
|
|
fd.write(' & ')
|
|
|
|
fd.write('\\hline')
|
|
|
|
curr_date = date(start_year, month, 01)
|
|
weekline = " " + " &" * curr_date.weekday()
|
|
next_date = curr_date
|
|
while curr_date.month == next_date.month:
|
|
curr_date = next_date
|
|
next_date = curr_date + timedelta(days=1)
|
|
|
|
weekline = weekline + " " + str(curr_date.day)
|
|
if (curr_date.weekday() == 6): # sunday
|
|
weekline = weekline + "\\\\\n\r "
|
|
else:
|
|
weekline = weekline + "&"
|
|
|
|
weekline = weekline + (" &" * (5 - curr_date.weekday())) + "\\\\\n\r"
|
|
|
|
fd.write(weekline)
|
|
|
|
fd.write('''
|
|
\\end{tabular}
|
|
\\end{minipage}''')
|
|
# if (month == 6):
|
|
# fd.write('\\newpage\n\r')
|
|
|
|
fd.write('''
|
|
% end overview calender
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
''')
|
|
|
|
|
|
def tex_write_weekly(fd):
|
|
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():
|
|
from PyPDF2 import PdfFileReader
|
|
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()
|