-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_schedule.py
58 lines (45 loc) · 2.43 KB
/
process_schedule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pandas as pd
import datetime
import json
import dataframe_image as dfi
import csv
def extract_next_week_schedule(promotion):
if promotion == "M2S3 23-24":
old_schedule = pd.read_csv(
"/home/ubuntu/deployed_project/scraper_owncloud_geomatique/csv/M2.csv")
else:
old_schedule = pd.read_csv(
"/home/ubuntu/deployed_project/scraper_owncloud_geomatique/csv/M1.csv")
with open("/home/ubuntu/deployed_project/scraper_owncloud_geomatique/json/credentials.json", "r") as json_file:
data = json.load(json_file)
file_path = data["file_path"]
df = pd.read_excel("/home/ubuntu/deployed_project/scraper_owncloud_geomatique/schedule_spreadsheet/spreadsheet.xlsx",
skiprows=2, sheet_name=promotion)
today = datetime.date.today()
days_until_next_monday = (7 - today.weekday()) % 7
next_monday = today + datetime.timedelta(days=days_until_next_monday)
next_wensday = next_monday + datetime.timedelta(days=2)
next_week = df[(df["date"] >= next_monday.strftime('%Y-%m-%d'))
& (df["date"] <= next_wensday.strftime('%Y-%m-%d'))]
# Is there classes next wensday ? Used to state it in an email
classes_next_wensday = next_week["jour"].str.contains(
"mercredi").any()
next_week = next_week.reset_index(drop=True)
# style the df and export as image
if promotion == "M1S1 23-24":
# check if the schedule changed since last time
schedule_unchanged = old_schedule[["08h30 - 10h30", "10h30 - 12h30", "14h - 16h", "16h-18h"]].equals(
next_week[["08h30 - 10h30", "10h30 - 12h30", "14h - 16h", "16h-18h"]])
next_week.to_csv(
"/home/ubuntu/deployed_project/scraper_owncloud_geomatique/csv/M1.csv")
next_week = dfi.export(
next_week, "/home/ubuntu/deployed_project/scraper_owncloud_geomatique/M1.png")
elif promotion == "M2S3 23-24":
# check if the schedule changed since last time
schedule_unchanged = old_schedule[["8h30 - 10h30", "10h30 - 12h30", "14h - 16h", "16h-18h"]].equals(
next_week[["8h30 - 10h30", "10h30 - 12h30", "14h - 16h", "16h-18h"]])
next_week.to_csv(
"/home/ubuntu/deployed_project/scraper_owncloud_geomatique/csv/M2.csv")
next_week = dfi.export(
next_week, "/home/ubuntu/deployed_project/scraper_owncloud_geomatique/M2.png")
return [classes_next_wensday, schedule_unchanged]