Script HTML Template

Following project Flask Web Deployment on Google Cloud and Convert Schedule to .ics

Last this is a very sample template that allow running with Python script.

The structure is accepting input then, send input to backend Python generate result.

Note: you need to be careful when you use index.html with send_file function in Flask. The version of Flask need to be known when you deployment to GCP. And save it to static folder.

source code here

HTML

Your index.html file is the front-end part of your web application for converting schedules into ICS (iCalendar) format. Let's break down its components:

HTML Structure

DOCTYPE and HTML Tag

<!DOCTYPE html>
<html lang="en">

Head Section

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Schedule to ICS Converter</title>
</head>

Body Section

<body>
    <h1>Upload Your Schedule</h1>
    ...
</body>
<a href="https://my.wisc.edu/web/expanded" target="_blank">MyUW</a>
Form for Schedule Input
<form id="scheduleForm">
    ...
    <input type="submit" value="Generate ICS File">
</form>

JavaScript for Form Submission

Event Listener for Form Submission

document.getElementById('scheduleForm').addEventListener('submit', function(event) {
    ...
});

Form Data Collection and Fetch Request

const formData = new FormData(event.target);
...
fetch('https://schedule-maker-411505.uc.r.appspot.com/generate-ics', {
    ...
});

Handling the Server Response

.then(response => response.blob())
.then(blob => {
    ...
});

Error Handling

.catch(error => console.error('Error:', error));

Summary

The index.html file sets up a user interface for users to input their schedules and select date ranges. When the form is submitted, a JavaScript function collects this data and sends it to your Flask server. The server processes this data and returns a ZIP file containing the .ics files, which the front-end then automatically downloads. This setup provides a seamless user experience for converting schedule information into calendar files.