Initial prototype
This commit is contained in:
commit
b36ec7c403
144
main.py
Normal file
144
main.py
Normal file
|
@ -0,0 +1,144 @@
|
|||
import argparse
|
||||
import bottle
|
||||
|
||||
TEMPLATE_INDEX = '''
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>My calendar</title>
|
||||
<style>
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.week-counter {
|
||||
width: 2%;
|
||||
text-align: center;
|
||||
border-right: 1px lightgray solid;
|
||||
display: inline-block;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.calendar-grid {
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.calendar-weekday-header {
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
|
||||
border-bottom: 1px black solid;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.calendar-day {
|
||||
border-bottom: 1px lightgray solid;
|
||||
border-right: 1px lightgray solid;
|
||||
|
||||
min-height: 100px;
|
||||
font-size: 1rem;
|
||||
height: 18vh;
|
||||
}
|
||||
|
||||
.day-num.today {
|
||||
background-color: red;
|
||||
color: white;
|
||||
padding-right: 4px;
|
||||
border-radius: 7px;
|
||||
margin: 5px 1px;
|
||||
}
|
||||
|
||||
.calendar-day.weekend-day {
|
||||
background: pink;
|
||||
}
|
||||
|
||||
.calendar-day .day-num {
|
||||
text-align: right;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.calendar-day,.calendar-weekday-header {
|
||||
width: 14%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.month-header {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="month-header">August 2022</h1>
|
||||
<div class="calendar-grid">
|
||||
<div class="week-row">
|
||||
<div class="week-counter"></div>
|
||||
<div class="calendar-weekday-header">Monday</div>
|
||||
<div class="calendar-weekday-header">Tuesday</div>
|
||||
<div class="calendar-weekday-header">Wednesday</div>
|
||||
<div class="calendar-weekday-header">Thursday</div>
|
||||
<div class="calendar-weekday-header">Friday</div>
|
||||
<div class="calendar-weekday-header">Saturday</div>
|
||||
<div class="calendar-weekday-header">Sunday</div>
|
||||
|
||||
% for day_info in days:
|
||||
% if day_info['day_of_week'] == 1:
|
||||
</div><div class="week-row">
|
||||
<div class="week-counter
|
||||
">W{{ day_info['week_of_year'] }}</div>
|
||||
% end
|
||||
<div class="calendar-day
|
||||
% if day_info['is_weekend']:
|
||||
weekend-day
|
||||
% end
|
||||
"><div class="day-num
|
||||
% if day_info['today']:
|
||||
today
|
||||
% end
|
||||
">{{ day_info['day_of_month'] }}</div>
|
||||
% for event_text in day_info['events']:
|
||||
</br><span>{{ event_text }}</span>
|
||||
% end
|
||||
|
||||
</div>
|
||||
% end
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
|
||||
## Paths
|
||||
@bottle.route('/')
|
||||
def reddit_index():
|
||||
events_map = {
|
||||
19: ['J: Spil Fredagsbar', 'L: Datbar'],
|
||||
20: ['F: Regatta'],
|
||||
}
|
||||
|
||||
days = []
|
||||
for day_of_month in range(1, 31 + 1):
|
||||
day_of_week = (day_of_month - 1) % 7 + 1
|
||||
week_of_year = day_of_month // 7 + 1
|
||||
days.append({
|
||||
'day_of_month': day_of_month,
|
||||
'day_of_week': day_of_week,
|
||||
'is_weekend': day_of_week == 6 or day_of_week == 7,
|
||||
'week_of_year' : week_of_year,
|
||||
'today': day_of_month == 19,
|
||||
'events': events_map.get(day_of_month, []),
|
||||
})
|
||||
return bottle.template(TEMPLATE_INDEX, days = days)
|
||||
|
||||
## Argument parsing
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--hostname', action='store', default = 'localhost', dest='hostname')
|
||||
parser.add_argument('--port', action='store', default = 8080, dest='port', type = int)
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parser.parse_args()
|
||||
bottle.run(host=args.hostname, port=args.port)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user