Aevann1 2022-07-11 15:14:34 +02:00
parent bf1fec7918
commit 27b1ed83cc
3 changed files with 62 additions and 86 deletions

View File

@ -242,40 +242,6 @@ class Comment(Base):
if self.ghost: return '👻'
else: return self.author.username
@property
@lazy
def json_raw(self):
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
data= {
'id': self.id,
'level': self.level,
'author_name': self.author_name,
'body': self.body,
'body_html': self.body_html,
'is_bot': self.is_bot,
'created_utc': self.created_utc,
'edited_utc': self.edited_utc or 0,
'is_banned': bool(self.is_banned),
'deleted_utc': self.deleted_utc,
'is_nsfw': self.over_18,
'permalink': f'/comment/{self.id}',
'stickied': self.stickied,
'distinguish_level': self.distinguish_level,
'post_id': self.post.id if self.post else 0,
'score': self.score,
'upvotes': self.upvotes,
'downvotes': self.downvotes,
'is_bot': self.is_bot,
'flags': flags,
}
if self.ban_reason:
data["ban_reason"]=self.ban_reason
return data
@lazy
def award_count(self, kind, v):
if v and v.poor: return 0
@ -300,13 +266,36 @@ class Comment(Base):
'parent': self.parent_fullname
}
else:
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
data=self.json_raw
data= {
'id': self.id,
'level': self.level,
'author_name': self.author_name,
'body': self.body,
'body_html': self.body_html,
'is_bot': self.is_bot,
'created_utc': self.created_utc,
'edited_utc': self.edited_utc or 0,
'is_banned': bool(self.is_banned),
'deleted_utc': self.deleted_utc,
'is_nsfw': self.over_18,
'permalink': f'/comment/{self.id}',
'stickied': self.stickied,
'distinguish_level': self.distinguish_level,
'post_id': self.post.id if self.post else 0,
'score': self.score,
'upvotes': self.upvotes,
'downvotes': self.downvotes,
'is_bot': self.is_bot,
'flags': flags,
}
if self.level>=2: data['parent_comment_id']= self.parent_comment_id
if "replies" in self.__dict__:
data['replies']=[x.json_core for x in self.replies(None)]
if self.level >= 2: data['parent_comment_id'] = self.parent_comment_id
data['replies'] = [x.json_core for x in self.replies()]
return data

View File

@ -216,11 +216,30 @@ class Submission(Base):
@property
@lazy
def json_raw(self):
def json_core(self):
if self.is_banned:
return {'is_banned': True,
'deleted_utc': self.deleted_utc,
'ban_reason': self.ban_reason,
'id': self.id,
'title': self.title,
'permalink': self.permalink,
}
if self.deleted_utc:
return {'is_banned': bool(self.is_banned),
'deleted_utc': True,
'id': self.id,
'title': self.title,
'permalink': self.permalink,
}
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
data = {'author_name': self.author_name if self.author else '',
return {'author_name': self.author_name if self.author else '',
'permalink': self.permalink,
'shortlink': self.shortlink,
'is_banned': bool(self.is_banned),
@ -249,33 +268,6 @@ class Submission(Base):
'club': self.club,
}
if self.ban_reason:
data["ban_reason"]=self.ban_reason
return data
@property
@lazy
def json_core(self):
if self.is_banned:
return {'is_banned': True,
'deleted_utc': self.deleted_utc,
'ban_reason': self.ban_reason,
'id': self.id,
'title': self.title,
'permalink': self.permalink,
}
elif self.deleted_utc:
return {'is_banned': bool(self.is_banned),
'deleted_utc': True,
'id': self.id,
'title': self.title,
'permalink': self.permalink,
}
return self.json_raw
@property
@lazy
def json(self):
@ -288,7 +280,7 @@ class Submission(Base):
data["author"]='👻' if self.ghost else self.author.json_core
data["comment_count"]=self.comment_count
if "replies" in self.__dict__:
data["replies"]=[x.json_core for x in self.replies]

View File

@ -619,8 +619,19 @@ class User(Base):
@property
@lazy
def json_raw(self):
data = {'username': self.username,
def json_core(self):
if self.is_suspended:
return {'username': self.username,
'url': self.url,
'is_banned': True,
'is_permanent_ban': not bool(self.unban_utc),
'ban_reason': self.ban_reason,
'id': self.id
}
return {'username': self.username,
'url': self.url,
'is_banned': bool(self.is_banned),
'created_utc': self.created_utc,
@ -633,22 +644,6 @@ class User(Base):
'flair': self.customtitle
}
return data
@property
@lazy
def json_core(self):
now = int(time.time())
if self.is_suspended:
return {'username': self.username,
'url': self.url,
'is_banned': True,
'is_permanent_ban': not bool(self.unban_utc),
'ban_reason': self.ban_reason,
'id': self.id
}
return self.json_raw
@property
@lazy