Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/GSOC examples/birthday reminder37
1 files changed, 35 insertions, 2 deletions
diff --git a/data/GSOC examples/birthday reminder b/data/GSOC examples/birthday reminder
index 485136c..b66323a 100644
--- a/data/GSOC examples/birthday reminder
+++ b/data/GSOC examples/birthday reminder
@@ -112,6 +112,32 @@ def load_from_file(filename):
# Return that to whoever called load_from_file() in the first place.
return bday_dictionary
+# This function checks whether the string you entered is actually a date.
+# What are the things we check for?
+# What could also be checked? Is it possible to enter a future date now?
+def validate_date(user_input):
+ if len(user_input) != 8:
+ return False
+
+ try:
+ int(user_input)
+ except:
+ return False
+
+ if int(user_input) < 0:
+ return False
+
+ if int(user_input[0:2]) > 31:
+ return False
+
+ if int(user_input[2:4]) > 12:
+ return False
+
+ if int(user_input[4:8]) > int(time.strftime("%Y")):
+ return False
+
+ return True
+
# This function displays the menu which you see when you run the program.
def menu():
# Here we will store all the birthday data. Notice the {} - that's how we
@@ -153,14 +179,21 @@ def menu():
name = raw_input()
print "Enter " + name + "'s birthday (ddmmyyyy): "
birthday = raw_input()
- add_birthday(name, birthday, birthdays)
+ if validate_date(birthday):
+ add_birthday(name, birthday, birthdays)
+ else:
+ print "That is not a valid birthday."
elif choice == "5":
print "Enter your friend's name: "
name = raw_input()
print "Enter " + name + "'s birthday (ddmmyyyy): "
birthday = raw_input()
- change_birthday(name, birthday, birthdays)
+ if validate_date(birthday):
+ change_birthday(name, birthday, birthdays)
+ else:
+ print "That is not a valid birthday."
+
elif choice == "6":
print "Enter your friend's name: "