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.
141 lines
3.4 KiB
141 lines
3.4 KiB
#!/usr/bin/python3
|
|
# coding: utf-8
|
|
|
|
import math
|
|
import json
|
|
|
|
from datetime import timedelta
|
|
from datetime import date
|
|
import locale
|
|
import os
|
|
from tracemalloc import start
|
|
|
|
from umlauts import escape_german_umlauts
|
|
from dates import get_special_text
|
|
from yearly_view import tex_write_year_overview
|
|
|
|
start_year = 2022
|
|
months_start = 1
|
|
months_end = 6
|
|
add_clock = False
|
|
|
|
def compile_tex(filename):
|
|
cmd = 'pdflatex ' + filename
|
|
|
|
os.system(cmd)
|
|
#os.remove(os.path(filename).stem + ".aux")
|
|
#os.remove(os.path(filename).stem + ".log")
|
|
|
|
|
|
def main():
|
|
main_tex = "calender.tex"
|
|
# 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, start_year, add_clock)
|
|
|
|
tex_write_footer(fd)
|
|
|
|
fd.close()
|
|
compile_tex(main_tex)
|
|
|
|
|
|
|
|
def tex_write_header(fd):
|
|
start_fd = open("./vorlagen/week_2pages_start.tex", "r")
|
|
for line in start_fd:
|
|
fd.write(line)
|
|
fd.write("\\begin{document}\n");
|
|
return
|
|
|
|
|
|
def tex_write_footer(fd):
|
|
fd.write("\\end{document}\n");
|
|
return
|
|
|
|
|
|
def tex_write_weekly(fd, year, addclock):
|
|
start_date = date(year, months_start, 1)
|
|
end_date = date(year, months_end, 30)
|
|
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("%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
|
|
fd.write("% begin real calender \n");
|
|
|
|
curr_date = print_start_date;
|
|
|
|
print("year : " + str(curr_date.year))
|
|
|
|
last_year= ""
|
|
last_month= ""
|
|
|
|
while True:
|
|
if curr_date.weekday() == 0 or curr_date.weekday() == 3:
|
|
# new year to setup
|
|
if str(curr_date.year) != str(last_year):
|
|
last_year= curr_date.year
|
|
fd.write("\n\\renewcommand{\year}{"+ str(curr_date.year) +"}\n")
|
|
|
|
# new month to setup
|
|
if str(curr_date.month) != str(last_month):
|
|
last_month= curr_date.month
|
|
fd.write("\n\\renewcommand{\month}{" + curr_date.strftime('%B') + "}\n")
|
|
|
|
# should give
|
|
# \printweek{KW10}{1}{}{2}{}{3}{}
|
|
|
|
weeknumber = curr_date.strftime("%V")
|
|
daynumber = curr_date.strftime("%d")
|
|
devider = "\\newline \n"
|
|
special_text = get_special_text(curr_date, devider)
|
|
|
|
# check for new week
|
|
if curr_date.weekday() == 0: # monday
|
|
fd.write("\\printweek")
|
|
fd.write("{KW" + weeknumber + "}")
|
|
|
|
if curr_date.weekday() == 3: # thursday is on second page
|
|
fd.write("\n")
|
|
fd.write("\\newpage\n")
|
|
fd.write("\\printweekend")
|
|
fd.write("{KW" + weeknumber + "}")
|
|
|
|
|
|
# done for every day
|
|
fd.write("{" + daynumber + "}")
|
|
fd.write("{" + special_text + "}")
|
|
|
|
if curr_date.weekday() == 6: # sunday is end of week so close it
|
|
fd.write("\n")
|
|
|
|
# end of calender
|
|
if (print_end_date == curr_date):
|
|
break
|
|
|
|
#go to next day
|
|
next_date = curr_date + timedelta(days=1)
|
|
|
|
|
|
# use the new curr date and contiue
|
|
curr_date = next_date
|
|
|
|
# end of for each day
|
|
|
|
fd.write('''
|
|
% end real calender
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
''')
|
|
return
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|