-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrader.py
More file actions
31 lines (24 loc) · 899 Bytes
/
grader.py
File metadata and controls
31 lines (24 loc) · 899 Bytes
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
#!/usr/bin/python3
import sys
import os
from time import gmtime, strftime
import getpass
def main():
# Check the number of parameters.
if (len(sys.argv) != 4 and len(sys.argv) != 5):
sys.exit(2)
# Get the current username of the student.
username = getpass.getuser()
# Get the timestamp.
timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
# Get the rest of the parameters for the log.
new_entry = ""
if (len(sys.argv) == 4):
new_entry = f"{username} {timestamp} {sys.argv[1]} {sys.argv[2]} {sys.argv[3]}\n"
elif (len(sys.argv) == 5):
new_entry = f"{username} {timestamp} {sys.argv[1]} {sys.argv[2]} {sys.argv[3]} {sys.argv[4]}\n"
# Now, append to the logs, if they exist.
f = open(f"/home/{username}/.education/{username}_logs.txt", "a+")
f.write(new_entry)
f.close()
main()