initial commit
This commit is contained in:
commit
d437b5a882
2
Makefile
Normal file
2
Makefile
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
build:
|
||||||
|
g++ -I/usr/include/python3.11 -lpython3.11 main.cpp -o schedule
|
47
main.cpp
Normal file
47
main.cpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#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();
|
||||||
|
|
||||||
|
FILE *fd = fopen("main.py", "r");
|
||||||
|
PyRun_SimpleFileEx(fd, "main.py", 1);
|
||||||
|
|
||||||
|
Py_Finalize();
|
||||||
|
}
|
58
main.py
Normal file
58
main.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def get_id():
|
||||||
|
with open("id.txt", "r") as file:
|
||||||
|
return file.read()
|
||||||
|
|
||||||
|
def cleanse_hour(hour):
|
||||||
|
split_hour = hour.split(":", 1)
|
||||||
|
return (split_hour[0] if (len(split_hour[0]) == 2) else "0" + split_hour[0]) + split_hour[1]
|
||||||
|
|
||||||
|
def get_shift(schedule_day):
|
||||||
|
shift = schedule_day["DailyShift"][0]
|
||||||
|
if (shift == "-"):
|
||||||
|
return
|
||||||
|
|
||||||
|
datestr = schedule_day["StartDate"]
|
||||||
|
date = datestr[0:4] + datestr[5:7] + datestr[8:10] + "T"
|
||||||
|
|
||||||
|
split_shift = shift.split("-", 1)
|
||||||
|
startdate = date + cleanse_hour(split_shift[0]) + "00"
|
||||||
|
|
||||||
|
split_shift = split_shift[1].split(" ", 1)
|
||||||
|
enddate = date + cleanse_hour(split_shift[0]) + "00"
|
||||||
|
|
||||||
|
dept = split_shift[1]
|
||||||
|
|
||||||
|
return (startdate, enddate, dept)
|
||||||
|
|
||||||
|
sess = requests.Session()
|
||||||
|
|
||||||
|
employee_id = get_id()
|
||||||
|
|
||||||
|
sess.get("https://myschedule.metro.ca/api/Login/" + employee_id)
|
||||||
|
total_schedule = sess.get("https://myschedule.metro.ca/api/Employee/" + employee_id).json()
|
||||||
|
|
||||||
|
with open("calendar.ics", "w") as file:
|
||||||
|
file.write("BEGIN:VCALENDAR\n")
|
||||||
|
file.write("VERSION:2.0\n")
|
||||||
|
file.write("PRODID:SuperNovaa41\n")
|
||||||
|
|
||||||
|
for i in range(-1, -8, -1):
|
||||||
|
res = get_shift(total_schedule["WorkTime"][i])
|
||||||
|
if (res is None):
|
||||||
|
continue
|
||||||
|
|
||||||
|
with open("calendar.ics", "a") as file:
|
||||||
|
file.write("BEGIN:VEVENT\n")
|
||||||
|
file.write("DTSTART:" + res[0] + "\n")
|
||||||
|
file.write("DTEND:" + res[1] + "\n")
|
||||||
|
file.write("SUMMARY: Work (" + res[2] + ")\n")
|
||||||
|
file.write("END:VEVENT\n")
|
||||||
|
|
||||||
|
with open("calendar.ics", "a") as file:
|
||||||
|
file.write("END:VCALENDAR\n")
|
||||||
|
|
47
src/index.html
Normal file
47
src/index.html
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Metro Schedule Getter</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<style>
|
||||||
|
p {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
#content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
#entry {
|
||||||
|
position: relative;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
#id-btn {
|
||||||
|
background-color: #d81e05;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
function getSchedule()
|
||||||
|
{
|
||||||
|
window.location = "/schedule/" + document.getElementById("id").value;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<div id="content">
|
||||||
|
<div id="entry">
|
||||||
|
<img id="logo" src="https://myschedule.metro.ca/app/components/shared/img/metro.png">
|
||||||
|
</div>
|
||||||
|
<div id="entry">
|
||||||
|
<input type="text" id="id" name="Employee ID" />
|
||||||
|
<button id="id-btn" onclick="getSchedule()">Submit!</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user