Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL restapi parameter 변경사항 반영 #83

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 4 additions & 2 deletions resources/images/professor-ubuntu/server/getAssignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import base64

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

json_str = requests.get(
Urls.base_url+"/assignments/"+assignment_id+"/students-urls").text
Urls.base_url+"/assignments/"+assignment_id+"/urls").text
data_users_assigned = list(json.loads(json_str)) # json to list[dict]

dir_path = Urls.dir_path_professor
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
11 changes: 6 additions & 5 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,16 +55,17 @@ 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+"/students-urls").text
Urls.base_url+"/assignments/"+assignment_id+"/urls").text
data_users_assigned = list(json.loads(json_str))
due_date = assignment_info.due_date

# mkdir
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
Loading