initial commit

This commit is contained in:
2022-05-24 16:45:28 -05:00
commit f0578f858b
17 changed files with 287 additions and 0 deletions

3
app/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
from flask import Flask
app = Flask(__name__)
from app import views

BIN
app/static/hellovetica.ttf Executable file

Binary file not shown.

BIN
app/static/sun.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@@ -0,0 +1,118 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
@font-face {
font-family: "Hellovetica";
src: url("hellovetica.ttf") format("truetype");
}
.dashboard {
font-family: "Helvetica";
height: 699px;
width: 600px;
{#border-style: solid;#}
text-align: left;
font-size: 17px;
}
.panel {
position: relative;
height: 50%;
{#border-style: dotted;#}
verical-align: top;
/* height: 250px; */
width: 100%;
}
.panel.top {
height: 35%;
}
.panel.bottom {
height: 65%;
}
.subpanel {
position: relative;
height:100%;
width:48%;
display: inline-block;
text-align: center;
align-items: middle;
}
.weather-icon {
position: relative;
height: 100%;
width: 100%;
object-fit: scale-down;
}
.week {
/* height:100% */
}
.day {
border-style: solid;
display: inline-block;
min-height: 220px;
max-height: 220px;
width: 135px;
vertical-align: top;
margin: 1px;
align-items: center;
}
.day-title{
background-color: black;
text-align: center;
color: white;
text-transform: uppercase;
font-weight: bold;
}
.event {
margin: 3pt;
background-color: white;
border-style: solid;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="dashboard">
<div class="panel top">
<div class="subpanel">
{# <img class="weather-icon" src="sun.gif"></img>#}
</div>
<div class="subpanel" style="font-size: 60px;font-weight: bold;vertical-align:top; text-align:right;">
{{ today.strftime('%a') }}<br>
{{ today.strftime('%b %-d') }}<br>
{{ today.strftime('%Y') }}<br>
</div>
</div>
<div class="panel bottom week">
{% for day, event in days %}
<div class="day">
<div id="dotw-1" class="day-title">
{{ day.strftime('%A') }}
</div>
{% if event %}
<div class="event">
{{ event.summary.value }}<br>
{% if event.dtstart.value.strftime('%H') != "00" %}
{{ event.dtstart.value.strftime('%-I:%M %p') }}<br>{{ event.dtend.value.strftime('%-I:%M %p') }}
{% endif %}
</div>
{% endif %}
</div>
{% endfor %}
</div>
</div>
</body>
</html>

54
app/views.py Normal file
View File

@@ -0,0 +1,54 @@
from app import app
from datetime import datetime, timedelta
import os
import caldav
import datetime
from icalendar import cal, Event
import requests
url = os.getenv('caldav_url')
username = os.getenv('username')
password = os.getenv('password')
cal_id = os.getenv('cal_id')
def daterange(start_date, end_date):
for n in range(int((end_date - start_date).days)):
yield datetime.datetime.date(start_date + timedelta(n))
@app.route('/')
def hello_world():
date_obj = datetime.datetime.now()
start_of_week = date_obj - timedelta(days=date_obj.weekday()) # Monday
end_of_week = start_of_week + timedelta(days=7) # Sunday
with caldav.DAVClient(url=url, username=username, password=password) as client:
my_principal = client.principal()
calendars = my_principal.calendars()
calendar = my_principal.calendar(cal_id=cal_id)
events_fetched = calendar.date_search(
start=start_of_week, end=end_of_week, expand=False)
events_fetched_by_date = {}
for event in events_fetched:
value = event.vobject_instance.vevent.dtstart.value
if isinstance(value, datetime.datetime):
events_fetched_by_date[datetime.datetime.date(value)] = event
elif isinstance(value, datetime.date):
events_fetched_by_date[value] = event
else:
raise Exception
days = []
for single_date in daterange(start_of_week, end_of_week):
event = events_fetched_by_date.get(single_date)
if event:
days.append((single_date, event.vobject_instance.vevent))
else:
days.append((single_date,[]))
# breakpoint()
pass
# r = "<br>".join([event.vobject_instance.vevent.summary.value for event in events_fetched if event.vobject_instance.vevent.dtstart.value < datetime.now()])
return render_template("dashboard.html", days=days, today=datetime.datetime.now())