Skip to content

Commit 7f78460

Browse files
committed
Updated types.py to_dict methods
1 parent e1afb4f commit 7f78460

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

codeforces_api/types.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def de_json(cls, json_string):
323323
time_seconds = obj["timeSeconds"]
324324
opts = dict()
325325
if "blogEntry" in obj:
326-
opts["blogEntry"] = BlogEntry.de_json(obj["blogEntry"])
326+
opts["blog_entry"] = BlogEntry.de_json(obj["blogEntry"])
327327
if "comment" in obj:
328328
opts["comment"] = Comment.de_json(obj["comment"])
329329
return cls(time_seconds, opts)
@@ -334,7 +334,12 @@ def __init__(self, time_seconds, options):
334334
setattr(self, key, options[key])
335335

336336
def to_dict(self):
337-
return super().to_dict()
337+
dictionary = {"time_seconds": self.time_seconds}
338+
if "blog_entry" in self.__dict__.keys():
339+
dictionary["blog_entry"] = self.blog_entry.to_dict()
340+
if "comment" in self.__dict__.keys():
341+
dictionary["comment"] = self.blog_entry.to_dict()
342+
return dictionary
338343

339344

340345
class RatingChange(JSONDeserializable, Dictionaryable):
@@ -538,7 +543,7 @@ def __init__(
538543

539544
def to_dict(self):
540545
return {
541-
"members": self.members,
546+
"members": [member.to_dict() for member in self.members],
542547
"participant_type": self.participant_type,
543548
"ghost": self.ghost,
544549
"team_id": self.team_id,
@@ -560,6 +565,9 @@ def de_json(cls, json_string):
560565
def __init__(self, handle):
561566
self.handle = handle
562567

568+
def to_dict(self):
569+
return {"handle": self.handle}
570+
563571

564572
class Problem(JSONDeserializable, Dictionaryable):
565573
@classmethod
@@ -706,8 +714,8 @@ def to_dict(self):
706714
"id": self.id,
707715
"creation_time_seconds": self.creation_time_seconds,
708716
"relative_time_seconds": self.relative_time_seconds,
709-
"problem": self.problem,
710-
"author": self.author,
717+
"problem": self.problem.to_dict(),
718+
"author": self.author.to_dict(),
711719
"programming_language": self.programming_language,
712720
"testset": self.testset,
713721
"passed_test_count": self.passed_test_count,
@@ -768,9 +776,9 @@ def to_dict(self):
768776
return {
769777
"id": self.id,
770778
"creation_time_seconds": self.creation_time_seconds,
771-
"hacker": self.hacker,
772-
"defender": self.defender,
773-
"problem": self.problem,
779+
"hacker": self.hacker.to_dict(),
780+
"defender": self.defender.to_dict(),
781+
"problem": self.problem.to_dict(),
774782
"verdict": self.verdict,
775783
"test": self.test,
776784
"judge_protocol": self.judge_protocol,
@@ -826,13 +834,15 @@ def __init__(
826834

827835
def to_dict(self):
828836
return {
829-
"party": self.party,
837+
"party": self.party.to_dict(),
830838
"rank": self.rank,
831839
"points": self.points,
832840
"penalty": self.penalty,
833841
"successful_hack_count": self.successful_hack_count,
834842
"unsuccessful_hack_count": self.unsuccessful_hack_count,
835-
"problem_results": self.problem_results,
843+
"problem_results": [
844+
problem_result.to_dict() for problem_result in self.problem_results
845+
],
836846
"last_submission_time_seconds": self.last_submission_time_seconds,
837847
}
838848

codeforces_api/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.2"
1+
__version__ = "2.0.3"

0 commit comments

Comments
 (0)