|  | @ -1,19 +1,53 @@ | 
		
	
		
			
				|  |  | #!/usr/bin/python |  |  | #!/usr/bin/python | 
		
	
		
			
				|  |  |  |  |  | import math | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | from datetime import timedelta |  |  | from datetime import timedelta | 
		
	
		
			
				|  |  | from datetime import date |  |  | from datetime import date | 
		
	
		
			
				|  |  | import locale |  |  | import locale | 
		
	
		
			
				|  |  |  |  |  | import os | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | start_year = 2020 |  |  |  | 
		
	
		
			
				|  |  |  |  |  | start_year = 2019 | 
		
	
		
			
				|  |  | start_date = date(start_year, 01, 01) |  |  | start_date = date(start_year, 01, 01) | 
		
	
		
			
				|  |  | end_date = date(start_year, 12, 31) |  |  | 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(): |  |  | def main(): | 
		
	
		
			
				|  |  |     # german |  |  |     # german | 
		
	
		
			
				|  |  |     locale.setlocale(locale.LC_TIME, "de_DE") |  |  |     locale.setlocale(locale.LC_TIME, "de_DE") | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  |     fd = open("calender.tex", "w") |  |  |  | 
		
	
		
			
				|  |  |  |  |  |     fd = open(main_tex, "w") | 
		
	
		
			
				|  |  |     tex_write_header(fd) |  |  |     tex_write_header(fd) | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  |     tex_write_calender_overview(fd) |  |  |     tex_write_calender_overview(fd) | 
		
	
	
		
			
				|  | @ -22,6 +56,14 @@ def main(): | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  |     tex_write_footer(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): |  |  | def tex_write_header(fd): | 
		
	
		
			
				|  |  |     # \usepackage{fontspec}{} |  |  |     # \usepackage{fontspec}{} | 
		
	
	
		
			
				|  | @ -55,6 +97,8 @@ def tex_write_header(fd): | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | def tex_write_footer(fd): |  |  | def tex_write_footer(fd): | 
		
	
		
			
				|  |  |     fd.write(''' |  |  |     fd.write(''' | 
		
	
		
			
				|  |  |  |  |  | \\ \\newpage | 
		
	
		
			
				|  |  |  |  |  | \\ \\newpage | 
		
	
		
			
				|  |  | \\end{document} |  |  | \\end{document} | 
		
	
		
			
				|  |  | ''') |  |  | ''') | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
	
		
			
				|  | @ -165,6 +209,13 @@ def tex_write_weekly(fd): | 
		
	
		
			
				|  |  |                 fd.write('~' + last_weekday.strftime('%Y')) |  |  |                 fd.write('~' + last_weekday.strftime('%Y')) | 
		
	
		
			
				|  |  |             fd.write('\\hrule') |  |  |             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(''' |  |  |         fd.write(''' | 
		
	
		
			
				|  |  |     \\parbox[t][0.115\\paperheight]{\\textwidth}{ |  |  |     \\parbox[t][0.115\\paperheight]{\\textwidth}{ | 
		
	
		
			
				|  |  |         \\flushleft |  |  |         \\flushleft | 
		
	
	
		
			
				|  | @ -193,6 +244,7 @@ def tex_write_weekly(fd): | 
		
	
		
			
				|  |  |         # start new page if sunday |  |  |         # start new page if sunday | 
		
	
		
			
				|  |  |         if curr_date.weekday() == 6: |  |  |         if curr_date.weekday() == 6: | 
		
	
		
			
				|  |  |             fd.write('\\newpage\n\r') |  |  |             fd.write('\\newpage\n\r') | 
		
	
		
			
				|  |  |  |  |  |             fd.write('\\color{' + color_lines + '}') | 
		
	
		
			
				|  |  |             for i in range(1, 18): |  |  |             for i in range(1, 18): | 
		
	
		
			
				|  |  |                 fd.write('\\hspace{8mm}\n\r') |  |  |                 fd.write('\\hspace{8mm}\n\r') | 
		
	
		
			
				|  |  |                 fd.write('\\myhrulefill{0.5pt}\n\r') |  |  |                 fd.write('\\myhrulefill{0.5pt}\n\r') | 
		
	
	
		
			
				|  | @ -204,5 +256,105 @@ def tex_write_weekly(fd): | 
		
	
		
			
				|  |  |     ''') |  |  |     ''') | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  | 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__": |  |  | if __name__ == "__main__": | 
		
	
		
			
				|  |  |     main() |  |  |     main() | 
		
	
		
			
				|  |  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |  |     combine_a7() |