Update calendar_app.py
Browse files- calendar_app.py +124 -30
calendar_app.py
CHANGED
|
@@ -113,6 +113,15 @@ class Calendar:
|
|
| 113 |
print(f"{print_counter}. {dt} {event_description}")
|
| 114 |
print_counter+=1
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
def check_valid_date(date):
|
| 118 |
"""Input sanitation for valid date format"""
|
|
@@ -147,9 +156,29 @@ class Calendar:
|
|
| 147 |
else:
|
| 148 |
return "valid_date"
|
| 149 |
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
if __name__ == "__main__":
|
|
@@ -166,38 +195,103 @@ if __name__ == "__main__":
|
|
| 166 |
print("7. Exit")
|
| 167 |
choice = input("Choose an option number: ")
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
calendar.add_reminder(date, reminder)
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
reminder = input("Enter description for event reminder: ")
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
calendar.
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
| 197 |
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
else:
|
| 203 |
print("Invalid option. Please try again.")
|
|
|
|
| 113 |
print(f"{print_counter}. {dt} {event_description}")
|
| 114 |
print_counter+=1
|
| 115 |
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def check_valid_menu_choice(choice):
|
| 119 |
+
"""Input sanitation for valid menu choice from 1 and 7."""
|
| 120 |
+
if not choice.isdigit() or int(choice) < 1 or int(choice) > 7:
|
| 121 |
+
print(f"Invalid choice: {choice}. Please choose an option number from 1 to 7.")
|
| 122 |
+
return "invalid_choice"
|
| 123 |
+
else:
|
| 124 |
+
return "valid_choice"
|
| 125 |
|
| 126 |
def check_valid_date(date):
|
| 127 |
"""Input sanitation for valid date format"""
|
|
|
|
| 156 |
else:
|
| 157 |
return "valid_date"
|
| 158 |
|
| 159 |
+
def check_valid_date_range(date_start, date_end):
|
| 160 |
+
"""Input sanitation for start date before OR equal to the end date."""
|
| 161 |
+
if datetime.strptime(date_start, '%Y-%m-%d') > datetime.strptime(date_end, '%Y-%m-%d'):
|
| 162 |
+
print(f"Error: Start date {date_start} is after end date {date_end}.\nPlease enter end date after the start date {date_start}.")
|
| 163 |
+
return "invalid_range"
|
| 164 |
+
else:
|
| 165 |
+
return "valid_range"
|
| 166 |
|
| 167 |
+
def check_valid_month(month):
|
| 168 |
+
"""Input sanitation for month string between 1 and 12."""
|
| 169 |
+
if not month.isdigit() or int(month) < 1 or int(month) > 12:
|
| 170 |
+
print(f"Invalid month: {month}. Please enter a month from 01 to 12.")
|
| 171 |
+
return "invalid_month"
|
| 172 |
+
else:
|
| 173 |
+
return "valid_month"
|
| 174 |
|
| 175 |
+
def check_valid_reminder(reminder):
|
| 176 |
+
"""Input sanitation for reminder description."""
|
| 177 |
+
if len(reminder)<1 or reminder is None:
|
| 178 |
+
print("Error: Reminder description cannot be empty.")
|
| 179 |
+
return "invalid_reminder"
|
| 180 |
+
else:
|
| 181 |
+
return "valid_reminder"
|
| 182 |
|
| 183 |
|
| 184 |
if __name__ == "__main__":
|
|
|
|
| 195 |
print("7. Exit")
|
| 196 |
choice = input("Choose an option number: ")
|
| 197 |
|
| 198 |
+
if check_valid_menu_choice(choice) == "valid_choice":
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
########################################
|
| 202 |
+
# user create event reminder
|
| 203 |
+
if choice == "1":
|
| 204 |
+
while True:
|
| 205 |
+
date = input("Enter date (YYYY-MM-DD): ")
|
| 206 |
+
if check_valid_date(date) == "invalid_date":
|
| 207 |
+
continue
|
| 208 |
+
else:
|
| 209 |
+
break
|
| 210 |
+
|
| 211 |
+
while True:
|
| 212 |
+
reminder = input("Enter description for event reminder: ")
|
| 213 |
+
if check_valid_reminder(reminder) == "invalid_reminder":
|
| 214 |
+
continue
|
| 215 |
+
else:
|
| 216 |
+
break
|
| 217 |
+
|
| 218 |
calendar.add_reminder(date, reminder)
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
elif choice == "2":
|
| 226 |
+
while True:
|
| 227 |
+
date_start = input("Enter start date (YYYY-MM-DD): ")
|
| 228 |
+
if check_valid_date(date_start) == "invalid_date":
|
| 229 |
+
continue
|
| 230 |
+
else:
|
| 231 |
+
break
|
| 232 |
+
|
| 233 |
+
while True:
|
| 234 |
+
date_end = input("Enter end date (YYYY-MM-DD): ")
|
| 235 |
+
if check_valid_date(date_end) == "invalid_date":
|
| 236 |
+
continue
|
| 237 |
+
else:
|
| 238 |
+
if check_valid_date_range(date_start, date_end) == "invalid_range":
|
| 239 |
+
continue
|
| 240 |
+
else:
|
| 241 |
+
break
|
| 242 |
+
|
| 243 |
+
while True:
|
| 244 |
reminder = input("Enter description for event reminder: ")
|
| 245 |
+
if check_valid_reminder(reminder) == "invalid_reminder":
|
| 246 |
+
continue
|
| 247 |
+
else:
|
| 248 |
+
break
|
| 249 |
+
|
| 250 |
+
calendar.add_daterange(date_start, date_end, reminder)
|
| 251 |
+
########################################
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
########################################
|
| 255 |
+
# list ALL or future reminders
|
| 256 |
+
elif choice == "3":
|
| 257 |
+
calendar.show_all_reminders()
|
| 258 |
+
elif choice == "4":
|
| 259 |
+
calendar.show_future_reminders()
|
| 260 |
+
########################################
|
| 261 |
+
|
| 262 |
|
| 263 |
|
| 264 |
+
########################################
|
| 265 |
+
# list reminders for specific date or month
|
| 266 |
+
elif choice == "5":
|
| 267 |
+
while True:
|
| 268 |
+
date = input("Enter date (YYYY-MM-DD): ")
|
| 269 |
+
if check_valid_date(date) == "invalid_date":
|
| 270 |
+
continue
|
| 271 |
+
else:
|
| 272 |
+
break
|
| 273 |
+
|
| 274 |
+
calendar.show_reminders(date)
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
elif choice == "6":
|
| 280 |
+
while True:
|
| 281 |
+
user_mth = input("Enter month number (MM): ")
|
| 282 |
+
if check_valid_month(month) == "invalid_month":
|
| 283 |
+
continue
|
| 284 |
+
else:
|
| 285 |
+
break
|
| 286 |
+
|
| 287 |
+
calendar.show_month(user_mth)
|
| 288 |
+
########################################
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
elif choice == "7":
|
| 293 |
+
calendar.save_calendar()
|
| 294 |
+
break
|
| 295 |
+
|
| 296 |
else:
|
| 297 |
print("Invalid option. Please try again.")
|