├── .devcontainer ├── devcontainer.json └── install.sh ├── LICENSE ├── README.rst ├── example_life_calendar.pdf └── generate_life_calendar.py /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "mcr.microsoft.com/vscode/devcontainers/base:ubuntu", // ubuntu LTS latest 3 | "onCreateCommand": "bash .devcontainer/install.sh", 4 | "extensions": [ 5 | "james-yu.latex-workshop" // Display pdf in VSCode 6 | ] 7 | } -------------------------------------------------------------------------------- /.devcontainer/install.sh: -------------------------------------------------------------------------------- 1 | sudo apt update -y; 2 | sudo apt install python3 -y; 3 | sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1; // make python3 default 4 | sudo apt install libcairo2-dev -y; // cairo dependancy 5 | sudo apt install python3-pip -y; 6 | pip3 install pycairo; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | Copyright 2017 Erik K Nyquist 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Personalised Life Calendar Generator 2 | ==================================== 3 | 4 | I'm a fan of the 5 | `Life Calendars `_ that 6 | can be found on Tim Urban's website www.waitbutwhy.com. It's basically a 7 | calendar for your whole life on a single poster, with a single box representing 8 | a week, a single row represrenting a year (52 boxes), and 90 rows for a total 9 | of 90 years. 10 | 11 | I liked having it on my wall, and for a while I tried using it to mark 12 | significant past events, as well as future goals & plans. There are a couple of 13 | practical problems with this, however, because of the current design of the 14 | Life Calendars. The main problem is that there are no real date references on 15 | the poster, unless you write them in yourself, so honing in on a specific box 16 | (say, the week you're currently in right now) is tedious and error-prone. 17 | 18 | The reason for this is obvious; the dates shown would be specific to your own 19 | birthday, so you can't make one poster for everybody if there are dates on it. 20 | The minimalist design of the poster kind of compensates for this, since you are 21 | left with plenty of room to write/draw whatever you want. Fair enough. 22 | 23 | I'm lazy, though. I don't want to write all those dates in. Plus, if I lose or 24 | damage the poster, I'd have to do all that work again. So I did this instead. 25 | 26 | This script takes your birthday as an argument, and generates a .pdf file 27 | containing a life calendar annotated with your personal dates. (Document size 28 | is 29x40 inches, for best printing results) 29 | 30 | Several additional features make navigation through the calendar a bit easier; 31 | 32 | 1. Rather than just starting exactly on your birthday, it starts on the last 33 | Monday before your birthday (i.e. the first day of the week you were born). 34 | This makes it much easier to identify which box holds a particular date, since 35 | every box starts with a Monday and represents "the week starting on " 36 | 37 | 2. For each row, the date of the first day of the first box in the row is 38 | printed on the right hand side. This date is always a Monday, as explained in 39 | #1. 40 | 41 | 3. Boxes containing your birthday are shaded 42 | 43 | 4. Boxes containing the first day of the year are shaded (a different shade) 44 | 45 | 5. Number of calendar rows (years) is configurable between 90-100 46 | 47 | Installation 48 | ============ 49 | 50 | Dependencies 51 | ------------ 52 | 53 | You must install ``pycairo`` before you can generate a 54 | Life Calendar: 55 | 56 | * `PyCairo `_ (Python library for drawing 57 | stuff & generating documents/images) 58 | 59 | :: 60 | 61 | pip install pycairo 62 | 63 | Or if you're running something like Debian/Ubuntu: 64 | 65 | :: 66 | 67 | sudo apt-get install python-cairo 68 | 69 | If you are getting ``Error: out of memory`` when running pycairo on windows after installing with pip, 70 | try instead installing from `this archive of pre-built pycairo wheels for windows `_. 71 | Make sure to pick the right wheel for your system, i.e. if you are using 64-bit python 3.11, 72 | you should pick ``pycairo-1.21.0-cp311-cp311-win_amd64.whl``. 73 | 74 | Download 75 | -------- 76 | 77 | Clone this repo to get the ``generate_life_calendar.py`` script 78 | 79 | :: 80 | 81 | $> git clone https://github.com/eriknyquist/generate_life_calendar 82 | 83 | Usage 84 | ===== 85 | 86 | After cloning this repo, run the script, passing in your birth date (format 87 | can be either dd-mm-yyyy or dd/mm/yyyy) 88 | 89 | :: 90 | 91 | $> cd generate_life_calendar 92 | $> python generate_life_calendar.py "23/10/1990" 93 | 94 | Created life_calendar.pdf 95 | 96 | By default, the output will be a file called ``life_calendar.pdf``. You can 97 | change the output filename with the ``-f`` option 98 | 99 | :: 100 | 101 | $> python generate_life_calendar.py "23/10/1990" -f my_life_calendar.pdf 102 | 103 | Created my_life_calendar.pdf 104 | 105 | If you would like to fill in the squares for past weeks but don't want to do 106 | this by hand, just pass the ``-d`` option to darken past weeks 107 | 108 | :: 109 | 110 | $> python generate_life_calendar.py "23/10/1990" -d 111 | 112 | Created life_calendar.pdf 113 | -------------------------------------------------------------------------------- /example_life_calendar.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eriknyquist/generate_life_calendar/fe65bf470bfc4ecaec45e0c98e708fd426066909/example_life_calendar.pdf -------------------------------------------------------------------------------- /generate_life_calendar.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import calendar 3 | import argparse 4 | import sys 5 | import os 6 | import math 7 | 8 | import cairo 9 | 10 | 11 | # A1 standard international paper size 12 | DOC_WIDTH = 1683 # 594mm / 23 3/8 inches 13 | DOC_HEIGHT = 2383 # 841mm / 33 1/8 inches 14 | 15 | DOC_NAME = "life_calendar.pdf" 16 | 17 | KEY_NEWYEAR_DESC = "First week of the new year" 18 | KEY_BIRTHDAY_DESC = "Week of your birthday" 19 | 20 | XAXIS_DESC = "Weeks of the year" 21 | YAXIS_DESC = "Years of your life" 22 | 23 | FONT = "Brocha" 24 | BIGFONT_SIZE = 40 25 | SMALLFONT_SIZE = 16 26 | TINYFONT_SIZE = 14 27 | 28 | MAX_TITLE_SIZE = 30 29 | DEFAULT_TITLE = "LIFE CALENDAR" 30 | 31 | Y_MARGIN = 144 32 | BOX_MARGIN = 6 33 | 34 | MIN_AGE = 80 35 | MAX_AGE = 100 36 | 37 | 38 | BOX_LINE_WIDTH = 3 39 | NUM_COLUMNS = 52 40 | 41 | BIRTHDAY_COLOUR = (0.5, 0.5, 0.5) 42 | NEWYEAR_COLOUR = (0.8, 0.8, 0.8) 43 | DARKENED_COLOUR_DELTA = (-0.4, -0.4, -0.4) 44 | 45 | ARROW_HEAD_LENGTH = 36 46 | ARROW_HEAD_WIDTH = 8 47 | 48 | 49 | def parse_date(date): 50 | formats = ['%d/%m/%Y', '%d-%m-%Y'] 51 | 52 | for f in formats: 53 | try: 54 | ret = datetime.datetime.strptime(date.strip(), f) 55 | except ValueError: 56 | continue 57 | else: 58 | return ret 59 | 60 | raise ValueError("Incorrect date format: must be dd-mm-yyyy or dd/mm/yyyy") 61 | 62 | 63 | def draw_square(ctx, pos_x, pos_y, box_size, fillcolour=(1, 1, 1)): 64 | """ 65 | Draws a square at pos_x,pos_y 66 | """ 67 | 68 | ctx.set_line_width(BOX_LINE_WIDTH) 69 | ctx.set_source_rgb(0, 0, 0) 70 | ctx.move_to(pos_x, pos_y) 71 | 72 | ctx.rectangle(pos_x, pos_y, box_size, box_size) 73 | ctx.stroke_preserve() 74 | 75 | ctx.set_source_rgb(*fillcolour) 76 | ctx.fill() 77 | 78 | 79 | def text_size(ctx, text): 80 | _, _, width, height, _, _ = ctx.text_extents(text) 81 | return width, height 82 | 83 | 84 | def back_up_to_monday(date): 85 | while date.weekday() != 0: 86 | date -= datetime.timedelta(days=1) 87 | return date 88 | 89 | 90 | def is_future(now, date): 91 | return now < date 92 | 93 | 94 | def is_current_week(now, month, day): 95 | end = now + datetime.timedelta(weeks=1) 96 | ret = [] 97 | 98 | for year in [now.year, now.year + 1]: 99 | try: 100 | date = datetime.datetime(year, month, day) 101 | except ValueError as e: 102 | if (month == 2) and (day == 29): 103 | # Handle edge case for birthday being on leap year day 104 | date = datetime.datetime(year, month, day - 1) 105 | else: 106 | raise e 107 | 108 | ret.append(now <= date < end) 109 | 110 | return True in ret 111 | 112 | 113 | def parse_darken_until_date(date): 114 | if date == 'today': 115 | today = datetime.date.today() 116 | until_date = datetime.datetime(today.year, today.month, today.day) 117 | else: 118 | until_date = parse_date(date) 119 | 120 | return back_up_to_monday(until_date) 121 | 122 | 123 | def get_darkened_fill(fill): 124 | return tuple(map(sum, zip(fill, DARKENED_COLOUR_DELTA))) 125 | 126 | 127 | def draw_row(ctx, pos_y, birthdate, date, box_size, x_margin, darken_until_date): 128 | """ 129 | Draws a row of 52 squares, starting at pos_y 130 | """ 131 | 132 | pos_x = x_margin 133 | 134 | for i in range(NUM_COLUMNS): 135 | fill = (1, 1, 1) 136 | 137 | if is_current_week(date, birthdate.month, birthdate.day): 138 | fill = BIRTHDAY_COLOUR 139 | elif is_current_week(date, 1, 1): 140 | fill = NEWYEAR_COLOUR 141 | 142 | if darken_until_date and is_future(date, darken_until_date): 143 | fill = get_darkened_fill(fill) 144 | 145 | draw_square(ctx, pos_x, pos_y, box_size, fillcolour=fill) 146 | pos_x += box_size + BOX_MARGIN 147 | date += datetime.timedelta(weeks=1) 148 | 149 | 150 | def draw_key_item(ctx, pos_x, pos_y, desc, box_size, colour): 151 | draw_square(ctx, pos_x, pos_y, box_size, fillcolour=colour) 152 | pos_x += box_size + (box_size / 2) 153 | 154 | ctx.set_source_rgb(0, 0, 0) 155 | w, h = text_size(ctx, desc) 156 | ctx.move_to(pos_x, pos_y + (box_size / 2) + (h / 2)) 157 | ctx.show_text(desc) 158 | 159 | return pos_x + w + (box_size * 2) 160 | 161 | 162 | def draw_grid(ctx, date, birthdate, age, darken_until_date): 163 | """ 164 | Draws the whole grid of 52x90 squares 165 | """ 166 | num_rows = age 167 | box_size = ((DOC_HEIGHT - (Y_MARGIN + 36)) / num_rows) - BOX_MARGIN 168 | x_margin = (DOC_WIDTH - ((box_size + BOX_MARGIN) * NUM_COLUMNS)) / 2 169 | 170 | start_date = date 171 | pos_x = x_margin / 4 172 | pos_y = pos_x 173 | 174 | # Draw the key for box colours 175 | ctx.set_font_size(TINYFONT_SIZE) 176 | ctx.select_font_face(FONT, cairo.FONT_SLANT_NORMAL, 177 | cairo.FONT_WEIGHT_NORMAL) 178 | 179 | pos_x = draw_key_item(ctx, pos_x, pos_y, KEY_BIRTHDAY_DESC, box_size, BIRTHDAY_COLOUR) 180 | draw_key_item(ctx, pos_x, pos_y, KEY_NEWYEAR_DESC, box_size, NEWYEAR_COLOUR) 181 | 182 | # draw week numbers above top row 183 | ctx.set_font_size(TINYFONT_SIZE) 184 | ctx.select_font_face(FONT, cairo.FONT_SLANT_NORMAL, 185 | cairo.FONT_WEIGHT_NORMAL) 186 | 187 | pos_x = x_margin 188 | pos_y = Y_MARGIN 189 | for i in range(NUM_COLUMNS): 190 | text = str(i + 1) 191 | w, h = text_size(ctx, text) 192 | ctx.move_to(pos_x + (box_size / 2) - (w / 2), pos_y - box_size) 193 | ctx.show_text(text) 194 | pos_x += box_size + BOX_MARGIN 195 | 196 | ctx.set_font_size(TINYFONT_SIZE) 197 | ctx.select_font_face(FONT, cairo.FONT_SLANT_ITALIC, 198 | cairo.FONT_WEIGHT_NORMAL) 199 | 200 | for i in range(num_rows): 201 | # Generate string for current date 202 | ctx.set_source_rgb(0, 0, 0) 203 | date_str = date.strftime('%d %b, %Y') 204 | w, h = text_size(ctx, date_str) 205 | 206 | # Draw it in front of the current row 207 | ctx.move_to(x_margin - w - box_size, 208 | pos_y + ((box_size / 2) + (h / 2))) 209 | ctx.show_text(date_str) 210 | 211 | # Draw the current row 212 | draw_row(ctx, pos_y, birthdate, date, box_size, x_margin, darken_until_date) 213 | 214 | # Increment y position and current date by 1 row/year 215 | pos_y += box_size + BOX_MARGIN 216 | date += datetime.timedelta(weeks=52) 217 | 218 | return x_margin 219 | 220 | def gen_calendar(birthdate, title, age, filename, darken_until_date, sidebar_text=None, 221 | subtitle_text=None): 222 | if len(title) > MAX_TITLE_SIZE: 223 | raise ValueError("Title can't be longer than %d characters" 224 | % MAX_TITLE_SIZE) 225 | 226 | age = int(age) 227 | if (age < MIN_AGE) or (age > MAX_AGE): 228 | raise ValueError("Invalid age, must be between %d and %d" % (MIN_AGE, MAX_AGE)) 229 | 230 | # Fill background with white 231 | surface = cairo.PDFSurface (filename, DOC_WIDTH, DOC_HEIGHT) 232 | ctx = cairo.Context(surface) 233 | 234 | ctx.set_source_rgb(1, 1, 1) 235 | ctx.rectangle(0, 0, DOC_WIDTH, DOC_HEIGHT) 236 | ctx.fill() 237 | 238 | ctx.select_font_face(FONT, cairo.FONT_SLANT_NORMAL, 239 | cairo.FONT_WEIGHT_BOLD) 240 | ctx.set_source_rgb(0, 0, 0) 241 | ctx.set_font_size(BIGFONT_SIZE) 242 | w, h = text_size(ctx, title) 243 | ctx.move_to((DOC_WIDTH / 2) - (w / 2), (Y_MARGIN / 2) - (h / 2)) 244 | ctx.show_text(title) 245 | 246 | if subtitle_text is not None: 247 | ctx.set_source_rgb(0.7, 0.7, 0.7) 248 | ctx.set_font_size(SMALLFONT_SIZE) 249 | w, h = text_size(ctx, subtitle_text) 250 | ctx.move_to((DOC_WIDTH / 2) - (w / 2), (Y_MARGIN / 2) - (h / 2) + 15) 251 | ctx.show_text(subtitle_text) 252 | 253 | date = back_up_to_monday(birthdate) 254 | 255 | # Draw 52x90 grid of squares 256 | x_margin = draw_grid(ctx, date, birthdate, age, darken_until_date) 257 | 258 | if sidebar_text is not None: 259 | # Draw text on sidebar 260 | w, h = text_size(ctx, sidebar_text) 261 | ctx.move_to((DOC_WIDTH - x_margin) + 20, Y_MARGIN + w + 100) 262 | ctx.set_font_size(SMALLFONT_SIZE) 263 | ctx.set_source_rgb(0.7, 0.7, 0.7) 264 | ctx.rotate(-90 * math.pi / 180) 265 | ctx.show_text(sidebar_text) 266 | 267 | ctx.show_page() 268 | 269 | 270 | def main(): 271 | parser = argparse.ArgumentParser(description='\nGenerate a personalized "Life ' 272 | ' Calendar", inspired by the calendar with the same name from the ' 273 | 'waitbutwhy.com store') 274 | 275 | parser.add_argument(type=parse_date, dest='date', help='starting date; your birthday,' 276 | 'in either yyyy/mm/dd or dd/mm/yyyy format (dashes \'-\' may also be used in ' 277 | 'place of slashes \'/\')') 278 | 279 | parser.add_argument('-f', '--filename', type=str, dest='filename', 280 | help='output filename', default=DOC_NAME) 281 | 282 | parser.add_argument('-t', '--title', type=str, dest='title', 283 | help='Calendar title text (default is "%s")' % DEFAULT_TITLE, 284 | default=DEFAULT_TITLE) 285 | 286 | parser.add_argument('-s', '--sidebar-text', type=str, dest='sidebar_text', 287 | help='Text to show along the right side of grid (default is no sidebar text)', 288 | default=None) 289 | 290 | parser.add_argument('-b', '--subtitle-text', type=str, dest='subtitle_text', 291 | help='Text to show under the calendar title (default is no subtitle text)', 292 | default=None) 293 | 294 | parser.add_argument('-a', '--age', type=int, dest='age', choices=range(MIN_AGE, MAX_AGE + 1), 295 | metavar='[%s-%s]' % (MIN_AGE, MAX_AGE), 296 | help=('Number of rows to generate, representing years of life'), 297 | default=90) 298 | 299 | parser.add_argument('-d', '--darken-until', type=parse_darken_until_date, dest='darken_until_date', 300 | nargs='?', const='today', help='Darken until date. ' 301 | '(defaults to today if argument is not given)') 302 | 303 | args = parser.parse_args() 304 | doc_name = '%s.pdf' % (os.path.splitext(args.filename)[0]) 305 | 306 | try: 307 | gen_calendar(args.date, args.title, args.age, doc_name, args.darken_until_date, 308 | sidebar_text=args.sidebar_text, subtitle_text=args.subtitle_text) 309 | except Exception as e: 310 | print("Error: %s" % e) 311 | return 312 | 313 | print('Created %s' % doc_name) 314 | 315 | if __name__ == "__main__": 316 | main() 317 | --------------------------------------------------------------------------------