diff --git a/src/repositories/bookings/repository.py b/src/repositories/bookings/repository.py index 3b80d00..4182b8c 100644 --- a/src/repositories/bookings/repository.py +++ b/src/repositories/bookings/repository.py @@ -95,6 +95,25 @@ async def form_schedule(self, start_of_week: datetime.date, from_user_id: int) - with open(Path(__file__).parent / "resources/Plain.svg", encoding="utf-8") as file: svg_string = file.read() + end = svg_string.index("", svg_string.index("month")) + svg_string = f"{svg_string[:end]}{dict({ + 1: "Jan", + 2: "Feb", + 3: "Mar", + 4: "Apr", + 5: "May", + 6: "Jun", + 7: "Jul", + 8: "Aug", + 9: "Sep", + 10: "Oct", + 11: "Nov", + 12: "Dec" + })[datetime.date.today().month]}{svg_string[end:]}" + + end = svg_string.index("", svg_string.index("monthnum")) + svg_string = f"{svg_string[:end]}{datetime.date.today().year % 100}{svg_string[end:]}" + weekdays_numbers, wide = await get_week_numbers(await self.is_start_of_week(start_of_week)) today = datetime.datetime.today().day @@ -102,12 +121,11 @@ async def form_schedule(self, start_of_week: datetime.date, from_user_id: int) - zip(weekdays_numbers, "monnum tuenum wednum thunum frinum satnum sunnum".split()) ): text = f""" - {identifier[:3].capitalize()} {number} """ @@ -189,14 +207,13 @@ async def form_schedule(self, start_of_week: datetime.date, from_user_id: int) - current_hour = datetime.datetime.now().hour cell_size = [124.161, 83.451] middle_offset = 17.739 + try: + end = svg_string.index(f"i{current_hour}") + end = svg_string.rfind('"opacity:', 0, end) + 8 + svg_string = f"{svg_string[:end]}1{svg_string[end + 1:]}" + except ValueError: + pass for booking in bookings: - if booking.time_start.hour == current_hour: - try: - end = svg_string.index(f"i{current_hour}") - end = svg_string.rfind('"opacity:', 0, end) + 8 - svg_string = f"{svg_string[:end]}1{svg_string[end + 1:]}" - except ValueError: - pass duration = count_duration(booking.time_start, booking.time_end) day = booking.time_start.weekday() coordinates = [ @@ -208,21 +225,20 @@ async def form_schedule(self, start_of_week: datetime.date, from_user_id: int) - symbol = f""" """ perceptual_text_y_offset = 5 perceptual_text_x_offset = -33.5 text_time_symbol = f""" - {booking.time_start.strftime('%H:%M')}-{booking.time_end.strftime('%H:%M')}""" text_alias_symbol = "" @@ -240,12 +256,19 @@ async def form_schedule(self, start_of_week: datetime.date, from_user_id: int) - y="{119.77097 + coordinates[1] + duration * (cell_size[1] - 2) / 2 + perceptual_text_y_offset * 2 + middle_offset}" style="font-style:normal;font-variant:normal;font-weight:normal; - font-stretch:normal;font-family:'Roboto';text-anchor:middle;-inkscape-font-specification:'Roboto'; + font-stretch:normal;font-family:'Roboto';text-anchor:middle; fill:#000000;fill-opacity:1;stroke:none;font-size:20px"> {alias}""" - end = svg_string.index(">", svg_string.index(">") + 1) + 1 + end = svg_string.rfind("<") svg_string = f"{svg_string[:end]}{symbol}{text_alias_symbol}{text_time_symbol}{svg_string[end:]}" - open("TEST.txt", "w").write(svg_string) + end = svg_string.rfind("<") + svg_string = f"""{svg_string[:end]}{svg_string[end:]}""" image_stream = io.BytesIO() svg2png(bytestring=svg_string, write_to=image_stream, scale=2) val = image_stream.getvalue() diff --git a/src/repositories/bookings/resources/Plain.svg b/src/repositories/bookings/resources/Plain.svg index f52fc20..86b6d11 100644 --- a/src/repositories/bookings/resources/Plain.svg +++ b/src/repositories/bookings/resources/Plain.svg @@ -9,158 +9,158 @@ xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> + width="190.87361" + height="79.451805" + x="16.999876" + y="120.771" + ry="0" + rx="0" /> + width="190.87361" + height="79.451805" + x="16.999876" + y="202.22281" + ry="0" + rx="0" /> + width="190.87361" + height="79.451797" + x="16.999876" + y="283.67462" + ry="0" + rx="0" /> + width="190.87361" + height="79.45179" + x="16.999876" + y="365.12643" + ry="0" + rx="0" /> + width="190.87361" + height="79.451813" + x="16.999876" + y="446.57822" + ry="0" + rx="0" /> + width="190.87361" + height="79.451805" + x="16.999876" + y="528.03003" + ry="0" + rx="0" /> + width="190.87361" + height="79.451767" + x="16.999876" + y="609.48187" + ry="0" + rx="0" /> + width="190.87361" + height="79.45179" + x="16.999876" + y="690.93365" + ry="0" + rx="0" /> + y="772.38544" + ry="0" + rx="0" /> + width="190.87363" + height="79.451782" + x="16.999876" + y="853.83728" + ry="0" + rx="0" /> + width="190.87363" + height="79.451836" + x="16.999876" + y="935.28906" + ry="0" + rx="0" /> + width="190.87363" + height="79.45192" + x="16.999876" + y="1016.7408" + ry="0" + rx="0" /> + width="190.87361" + height="79.451874" + x="16.999876" + y="1098.1926" + ry="0" + rx="0" /> + width="190.87361" + height="79.451767" + x="16.999876" + y="1179.6445" + ry="0" + rx="0" /> + width="190.87361" + height="79.45179" + x="16.999876" + y="1261.0963" + ry="0" + rx="0" /> + width="190.87361" + height="79.451782" + x="16.999876" + y="1342.5482" + ry="0" + rx="0" /> + width="190.8736" + height="79.450996" + x="16.999876" + y="1424" + ry="0" + rx="0" /> - OCT + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:42.6667px;font-family:Roboto;-inkscape-font-specification:'Roboto Bold';text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none"> 24 + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:42.6667px;font-family:Roboto;-inkscape-font-specification:Roboto;text-align:start;text-anchor:start;fill:#8f7e8a;fill-opacity:1;stroke:none"> :00 -