Sort comments by lines and update mail extraction

This commit is contained in:
Matej Focko 2020-05-25 23:49:52 +02:00
parent 2605c82ddf
commit 593bd0cf30
Signed by: mfocko
GPG key ID: 299B916A55682021
2 changed files with 15 additions and 2 deletions

View file

@ -2,6 +2,7 @@
import json
import math
from commands.base import BaseCommand
@ -22,6 +23,12 @@ class Comments(BaseCommand):
result[author].append(comment)
# sort by lines
for author in result:
result[author].sort(key=lambda comment:
comment["position"]["new_line"] if "position" in comment
else math.inf)
return result
@staticmethod

View file

@ -7,6 +7,8 @@ from typing import Dict, List
class Submission:
MAIL_CONTENT= re.compile(r"<pre>((.*\s+)+)<\/pre>")
def __init__(
self,
uco: str,
@ -44,8 +46,12 @@ class Submission:
self.flag = "LATE"
def get_mail(self) -> str:
match = re.search(r"<pre>((.*\s+)+)<\/pre>", self.mail)
return match.group(1) if match else self.mail
left = self.mail.find("<pre>")
right = self.mail.rfind("</pre>")
return self.mail[left + 5:right]
# print(self.mail)
# match = Submission.MAIL_CONTENT.search(self.mail)
# return match.group(1) if match else self.mail
def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None: