Skip to content

Commit

Permalink
[feat/#82] Fix: url restapi parameters adding lecture_id to funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
NayeonKeum committed Aug 31, 2023
1 parent 8b1ef8e commit 205bdf7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion resources/images/professor-ubuntu/server/cronjob.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
crontab -l > file1
echo "$1 $2 $3 $4 * /bin/bash /root/workdir/server/getAssignments.sh $5 > /proc/1/fd/1 2>/proc/1/fd/2" >> file1
echo "$1 $2 $3 $4 * /bin/bash /root/workdir/server/getAssignments.sh $5 $6 > /proc/1/fd/1 2>/proc/1/fd/2" >> file1
cat file1 | crontab -
rm -rf file1

Expand Down
4 changes: 3 additions & 1 deletion resources/images/professor-ubuntu/server/getAssignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import base64

assignment_id = sys.argv[1]
lecture_id = sys.argv[2]

json_str = requests.get(
Urls.base_url+"/assignments/"+assignment_id+"/urls").text
data_users_assigned = list(json.loads(json_str)) # json to list[dict]
Expand All @@ -20,7 +22,7 @@
encoded_dir_path_student = base64.b64encode((
dir_path_student+"/"+assignment_id).encode('ascii')).decode('ascii') # base64 encode
urlmodel = json.loads(requests.get(
Urls.base_url+"/urls/"+user["id"]).text)
Urls.base_url+"/users/"+user["id"]+"/"+lecture_id+"/url").text)
url = urlmodel["apiEndpoint"]+"/files/" + encoded_dir_path_student
json_str = requests.get(url).text
# json to dict
Expand Down
2 changes: 1 addition & 1 deletion resources/images/professor-ubuntu/server/getAssignments.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
source /etc/profile > /dev/null 2>&1
/usr/bin/python3 /root/workdir/server/getAssignments.py $1
/usr/bin/python3 /root/workdir/server/getAssignments.py $1 $2
9 changes: 5 additions & 4 deletions resources/images/professor-ubuntu/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
)


def schedule_cronjob(dt, assignment_id):
def schedule_cronjob(dt, assignment_id, lecture_id):
month, day, hour, minute = dt[1], dt[2], dt[3], dt[4]
os.system('/bin/bash %s/cronjob.sh %d %d %d %d %s' %
(os.path.dirname(os.path.realpath(__file__)), minute, hour, day, month, assignment_id))
os.system('/bin/bash %s/cronjob.sh %d %d %d %d %s %s' %
(os.path.dirname(os.path.realpath(__file__)), minute, hour, day, month, assignment_id, lecture_id))


def create_directories(assignment_id, data_users_assigned):
Expand All @@ -55,6 +55,7 @@ def create_directories(assignment_id, data_users_assigned):
@app.post("/assignments/")
async def create_assignment(assignment_info: Dto.AssignmentModel = None):
assignment_id = assignment_info.assignment_id
lecture_id = assignment_info.lecture_id
json_str = requests.get(
Urls.base_url+"/assignments/"+assignment_id+"/urls").text
data_users_assigned = list(json.loads(json_str))
Expand All @@ -64,7 +65,7 @@ async def create_assignment(assignment_info: Dto.AssignmentModel = None):
create_directories(assignment_id, data_users_assigned)

# cron
schedule_cronjob(due_date, assignment_id)
schedule_cronjob(due_date, assignment_id, lecture_id)

return True

Expand Down

0 comments on commit 205bdf7

Please sign in to comment.