forked from cyclohexane-2/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
53 lines (40 loc) · 1.18 KB
/
utils.py
File metadata and controls
53 lines (40 loc) · 1.18 KB
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
"""
Utility functions for StudentHub
"""
from datetime import datetime
import json
def format_date(date_string):
"""Convert date string to datetime object"""
# TODO: Add error handling for invalid date formats
return datetime.strptime(date_string, "%Y-%m-%d")
def calculate_days_remaining(deadline):
"""Calculate days remaining until deadline"""
today = datetime.now()
delta = deadline - today
return delta.days
def validate_grade(grade):
"""Validate if grade is between 0 and 100"""
if grade < 0 or grade > 100:
return False
return True
def save_to_json(data, filename):
"""Save data to JSON file"""
with open(filename, 'w') as f:
json.dump(data, f, indent=4)
def load_from_json(filename):
"""Load data from JSON file"""
try:
with open(filename, 'r') as f:
return json.load(f)
except FileNotFoundError:
return {}
def get_priority_level(days_remaining):
"""Determine priority based on days remaining"""
if days_remaining < 0:
return "OVERDUE"
elif days_remaining <= 3:
return "HIGH"
elif days_remaining <= 7:
return "MEDIUM"
else:
return "LOW"