Implement calendar display application

Built a full-featured smart display app with Flask backend and responsive frontend.

Features:
- Real-time clock display
- Weather integration (OpenWeatherMap API) for Hamilton, NZ
- Google Calendar integration (placeholder, needs credentials)
- Rotating background images from local directory
- Dad jokes display (icanhazdadjoke API)

Technical stack:
- Backend: Python Flask with API endpoints
- Frontend: HTML/CSS/JavaScript with auto-updating data
- Caching system to avoid API rate limits
- Responsive design for various screen sizes

Deployment ready for Raspberry Pi with systemd service and Chromium kiosk mode setup instructions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 17:23:11 +13:00
parent 4977016a64
commit ae11476245
11 changed files with 1083 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 MiB

306
static/css/style.css Normal file
View File

@@ -0,0 +1,306 @@
/* Reset and base styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
overflow: hidden;
width: 100vw;
height: 100vh;
color: #ffffff;
}
/* Background */
#background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
z-index: 0;
transition: background-image 1s ease-in-out;
}
#background::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.4);
z-index: 1;
}
/* Main container */
.container {
position: relative;
z-index: 2;
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
padding: 2rem;
}
/* Header */
.header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 2rem;
background: rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
padding: 1.5rem 2rem;
border-radius: 15px;
}
.time-display {
display: flex;
flex-direction: column;
}
.time {
font-size: 5rem;
font-weight: 300;
line-height: 1;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
.date {
font-size: 1.8rem;
font-weight: 300;
margin-top: 0.5rem;
opacity: 0.9;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}
.weather-summary {
display: flex;
align-items: center;
gap: 1rem;
}
.current-temp {
font-size: 4rem;
font-weight: 300;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
.weather-icon {
font-size: 4rem;
}
/* Main content */
.main-content {
flex: 1;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2rem;
overflow: hidden;
}
/* Sections */
section {
background: rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
padding: 2rem;
border-radius: 15px;
overflow-y: auto;
}
section h2 {
font-size: 2rem;
font-weight: 400;
margin-bottom: 1.5rem;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}
section h3 {
font-size: 1.5rem;
font-weight: 400;
margin: 1.5rem 0 1rem;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}
/* Weather Section */
.weather-description {
font-size: 1.8rem;
margin-bottom: 1rem;
text-transform: capitalize;
}
.weather-details {
display: flex;
flex-direction: column;
gap: 0.8rem;
margin: 1.5rem 0;
}
.weather-detail {
display: flex;
justify-content: space-between;
font-size: 1.3rem;
padding: 0.5rem 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.weather-detail .label {
opacity: 0.8;
}
/* Forecast */
.forecast-days {
display: flex;
flex-direction: column;
gap: 1rem;
}
.forecast-day {
display: grid;
grid-template-columns: 80px 1fr 120px;
align-items: center;
padding: 1rem;
background: rgba(255, 255, 255, 0.05);
border-radius: 10px;
gap: 1rem;
}
.forecast-day-name {
font-size: 1.3rem;
font-weight: 500;
}
.forecast-description {
font-size: 1.1rem;
opacity: 0.8;
text-transform: capitalize;
}
.forecast-temp {
font-size: 1.3rem;
text-align: right;
}
.forecast-temp .high {
font-weight: 500;
}
.forecast-temp .low {
opacity: 0.6;
margin-left: 0.5rem;
}
/* Calendar Section */
.events-list {
display: flex;
flex-direction: column;
gap: 1rem;
}
.event {
background: rgba(255, 255, 255, 0.05);
padding: 1.2rem;
border-radius: 10px;
border-left: 4px solid #4a9eff;
}
.event-time {
font-size: 1.1rem;
font-weight: 500;
margin-bottom: 0.5rem;
color: #4a9eff;
}
.event-title {
font-size: 1.4rem;
margin-bottom: 0.3rem;
}
.event-location {
font-size: 1rem;
opacity: 0.7;
font-style: italic;
}
.event-placeholder {
font-size: 1.2rem;
opacity: 0.6;
text-align: center;
padding: 2rem;
}
/* Footer */
.footer {
margin-top: 2rem;
background: rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
padding: 1.5rem 2rem;
border-radius: 15px;
}
.joke {
font-size: 1.2rem;
font-style: italic;
text-align: center;
opacity: 0.9;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}
/* Scrollbar styling */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.05);
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.2);
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.3);
}
/* Responsive adjustments for smaller screens */
@media (max-width: 1200px) {
.time {
font-size: 4rem;
}
.date {
font-size: 1.5rem;
}
.current-temp {
font-size: 3rem;
}
section h2 {
font-size: 1.6rem;
}
}
@media (max-width: 768px) {
.main-content {
grid-template-columns: 1fr;
}
.time {
font-size: 3rem;
}
.current-temp {
font-size: 2.5rem;
}
}

189
static/js/app.js Normal file
View File

@@ -0,0 +1,189 @@
// Update intervals (in milliseconds)
const INTERVALS = {
TIME: 1000, // 1 second
WEATHER: 900000, // 15 minutes
CALENDAR: 300000, // 5 minutes
BACKGROUND: 300000, // 5 minutes
JOKE: 3600000 // 1 hour
};
// Weather icon mapping (OpenWeatherMap icons to emoji or text)
const WEATHER_ICONS = {
'01d': '☀️', '01n': '🌙',
'02d': '⛅', '02n': '☁️',
'03d': '☁️', '03n': '☁️',
'04d': '☁️', '04n': '☁️',
'09d': '🌧️', '09n': '🌧️',
'10d': '🌦️', '10n': '🌧️',
'11d': '⛈️', '11n': '⛈️',
'13d': '❄️', '13n': '❄️',
'50d': '🌫️', '50n': '🌫️'
};
// Initialize the application
document.addEventListener('DOMContentLoaded', () => {
// Start all update functions
updateTime();
updateWeather();
updateCalendar();
updateBackground();
updateJoke();
// Set up intervals
setInterval(updateTime, INTERVALS.TIME);
setInterval(updateWeather, INTERVALS.WEATHER);
setInterval(updateCalendar, INTERVALS.CALENDAR);
setInterval(updateBackground, INTERVALS.BACKGROUND);
setInterval(updateJoke, INTERVALS.JOKE);
});
// Update time and date
function updateTime() {
const now = new Date();
// Format time (HH:MM)
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
document.getElementById('time').textContent = `${hours}:${minutes}`;
// Format date (Day, Month Date)
const options = { weekday: 'long', month: 'long', day: 'numeric' };
const dateString = now.toLocaleDateString('en-NZ', options);
document.getElementById('date').textContent = dateString;
}
// Fetch and update weather
async function updateWeather() {
try {
const response = await fetch('/api/weather');
if (!response.ok) throw new Error('Weather fetch failed');
const data = await response.json();
if (data.error) {
console.error('Weather error:', data.error);
return;
}
// Update current weather
const { current, forecast } = data;
document.getElementById('current-temp').textContent = `${current.temp}°`;
document.getElementById('weather-icon').textContent = WEATHER_ICONS[current.icon] || '🌤️';
document.getElementById('weather-description').textContent = current.description;
document.getElementById('feels-like').textContent = `${current.feels_like}°`;
document.getElementById('humidity').textContent = `${current.humidity}%`;
document.getElementById('wind-speed').textContent = `${current.wind_speed} km/h`;
// Update forecast
const forecastContainer = document.getElementById('forecast-container');
forecastContainer.innerHTML = '';
forecast.forEach(day => {
const dayElement = document.createElement('div');
dayElement.className = 'forecast-day';
dayElement.innerHTML = `
<div class="forecast-day-name">${day.date}</div>
<div class="forecast-description">${day.description}</div>
<div class="forecast-temp">
<span class="high">${day.temp_max}°</span>
<span class="low">${day.temp_min}°</span>
</div>
`;
forecastContainer.appendChild(dayElement);
});
} catch (error) {
console.error('Error updating weather:', error);
}
}
// Fetch and update calendar events
async function updateCalendar() {
try {
const response = await fetch('/api/calendar');
if (!response.ok) throw new Error('Calendar fetch failed');
const events = await response.json();
if (events.error) {
console.error('Calendar error:', events.error);
return;
}
const eventsContainer = document.getElementById('calendar-events');
if (!events || events.length === 0) {
eventsContainer.innerHTML = '<div class="event-placeholder">No upcoming events</div>';
return;
}
eventsContainer.innerHTML = '';
events.forEach(event => {
const eventElement = document.createElement('div');
eventElement.className = 'event';
const startTime = new Date(event.start);
const endTime = new Date(event.end);
// Format time
const timeOptions = { hour: '2-digit', minute: '2-digit', weekday: 'short', day: 'numeric', month: 'short' };
const timeString = startTime.toLocaleDateString('en-NZ', timeOptions);
eventElement.innerHTML = `
<div class="event-time">${timeString}</div>
<div class="event-title">${event.title}</div>
${event.location ? `<div class="event-location">📍 ${event.location}</div>` : ''}
`;
eventsContainer.appendChild(eventElement);
});
} catch (error) {
console.error('Error updating calendar:', error);
}
}
// Update background image
async function updateBackground() {
try {
const response = await fetch('/api/background');
if (!response.ok) throw new Error('Background fetch failed');
const data = await response.json();
const backgroundElement = document.getElementById('background');
if (data.image) {
// Preload image to avoid flicker
const img = new Image();
img.onload = () => {
backgroundElement.style.backgroundImage = `url('${data.image}')`;
};
img.src = data.image;
} else if (data.color) {
backgroundElement.style.backgroundColor = data.color;
backgroundElement.style.backgroundImage = 'none';
}
} catch (error) {
console.error('Error updating background:', error);
}
}
// Fetch and update dad joke
async function updateJoke() {
try {
const response = await fetch('/api/joke');
if (!response.ok) throw new Error('Joke fetch failed');
const data = await response.json();
if (data.joke) {
document.getElementById('joke').textContent = data.joke;
}
} catch (error) {
console.error('Error updating joke:', error);
}
}