repl.it
@tml/

SmoggyTightKnowledge

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3

import pendulum

today = pendulum.today()
start = today.start_of('month')
end = today.end_of('month')

# Yes, I will probably format this with yattag or jinja2
html="""
<html>
<head>
    <link rel="stylesheet" href="calendar.css" type="text/css" />
    <link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet">
</head>
<body>
    <table border="0" cellpadding="0" cellspacing="0" class="month">
        <tr>
        <th colspan="7" class="month">January 2019</th>
<tr>
"""

for day in start.start_of('week').diff(start.end_of('week')):
    html+='   <th class="{}">{}</th>\n'.format(day.format('ddd').lower(), day.format('ddd'))
html+='</tr>\n\n<tr>\n  '

for day in start.start_of('week').diff(end):
    if day < start:
        html+='<td class="noday">&nbsp;</td>\n'
        continue
    if day.day_of_week == day.end_of('week').day_of_week:
        html+='  <td class="{}">{}</td>\n</tr>\n\n'.format(day.format('ddd').lower(), day.format('DD'))
        html+='<tr>\n'
    else:
        html+='  <td class="{}">{}</td>\n'.format(day.format('ddd').lower(), day.format('DD'))

while day.add(days=1) < end.end_of('week'):
    html+='<td class="noday">&nbsp;</td>\n'
    day = day.add(days=1)

html+="""
        </table>
    </body>
</html>
"""

print(html)