This repository has been archived on 2025-02-17. You can view files and clone it, but cannot push or open issues or pull requests.

49 lines
954 B
C++
Raw Normal View History

2023-06-15 19:54:14 -04:00
#include "crow.h"
#include <string>
#include <Python.h>
#include <fstream>
void run_schedule_getter(std::string);
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")
([](){
crow::response main(200);
main.set_static_file_info("src/index.html");
main.set_header("content-type", "text/html");
return main;
});
CROW_ROUTE(app, "/schedule/<string>")
([](std::string id){
crow::response schedule(200);
run_schedule_getter(id);
schedule.set_static_file_info("calendar.ics");
schedule.set_header("content-type", "text/calendar");
schedule.set_header("content-disposition", "attachement; filename=\"work-schedule.ics\"");
return schedule;
});
app.port(18080).run();
return 0;
}
void run_schedule_getter(std::string id)
{
Py_Initialize();
std::ofstream file("id.txt");
file << id;
file.close();
2023-06-15 20:10:23 -04:00
FILE *fd = fopen("get_schedule.py", "r");
PyRun_SimpleFileEx(fd, "get_schedule.py", 1);
2023-06-17 16:54:20 -04:00
fclose(fd);
2023-06-15 19:54:14 -04:00
Py_Finalize();
}