1616
1717from importlib .resources import files
1818from packaging import version
19+ from datetime import datetime
20+ from pytz import timezone
1921from . import __version__ , CONFIG_LOADER
2022
2123# Internationalization
@@ -137,7 +139,7 @@ def prompt(honesty, included, excluded):
137139 # Show default message
138140 if honesty == True :
139141 honesty_question = _ (
140- "Keeping in mind the course's policy on academic honesty, "
142+ "Keeping in mind the course's policy on academic honesty, including its restrictions on AI use, "
141143 "are you sure you want to submit these files (yes/no)? "
142144 )
143145 # If a custom message is configured, show that instead
@@ -162,6 +164,26 @@ def prompt(honesty, included, excluded):
162164 return True
163165
164166
167+ def check_slug_year (slug ):
168+ """Warn if the slug is for previous year's CS50x course."""
169+
170+ # extract the year from the slug
171+ try :
172+ year = re .search (r"cs50/problems/(\d{4})/x" , slug )
173+ if year and int (year .group (1 )) < int (datetime .now (timezone ("US/Eastern" )).year ):
174+ suggested_slug = re .sub (r"cs50/problems/\d{4}/x" , f"cs50/problems/{ datetime .now (timezone ('US/Eastern' )).year } /x" , slug )
175+ cprint (_ ("You are submitting to a previous year's CS50x course. Your submission will not be counted towards this year's course." ), "yellow" )
176+ cprint (_ ("If you are looking to submit to this year's course, please use the following slug:" ), "yellow" )
177+ cprint (suggested_slug , "yellow" )
178+
179+ # Ask if they want to continue
180+ if not re .match (f"^\s*(?:{ _ ('y|yes' )} )\s*$" , input (_ ("Do you want to continue with this submission (yes/no)? " )), re .I ):
181+ raise Error (_ ("User aborted submission." ))
182+
183+ except ValueError :
184+ pass
185+
186+
165187def excepthook (type , value , tb ):
166188 """Report an exception."""
167189 if (issubclass (type , Error ) or issubclass (type , lib50 .Error )) and str (value ):
@@ -223,7 +245,8 @@ def main():
223245
224246 check_announcements ()
225247 check_version ()
226-
248+ check_slug_year (args .slug )
249+
227250 user_name , commit_hash , message = lib50 .push ("submit50" , args .slug , CONFIG_LOADER , prompt = prompt )
228251 print (message )
229252
0 commit comments