16
16
17
17
from importlib .resources import files
18
18
from packaging import version
19
+ from datetime import datetime
20
+ from pytz import timezone
19
21
from . import __version__ , CONFIG_LOADER
20
22
21
23
# Internationalization
@@ -137,7 +139,7 @@ def prompt(honesty, included, excluded):
137
139
# Show default message
138
140
if honesty == True :
139
141
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, "
141
143
"are you sure you want to submit these files (yes/no)? "
142
144
)
143
145
# If a custom message is configured, show that instead
@@ -162,6 +164,26 @@ def prompt(honesty, included, excluded):
162
164
return True
163
165
164
166
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
+
165
187
def excepthook (type , value , tb ):
166
188
"""Report an exception."""
167
189
if (issubclass (type , Error ) or issubclass (type , lib50 .Error )) and str (value ):
@@ -223,7 +245,8 @@ def main():
223
245
224
246
check_announcements ()
225
247
check_version ()
226
-
248
+ check_slug_year (args .slug )
249
+
227
250
user_name , commit_hash , message = lib50 .push ("submit50" , args .slug , CONFIG_LOADER , prompt = prompt )
228
251
print (message )
229
252
0 commit comments