master
HeyMoon 2022-08-20 17:18:44 -05:00
parent db5972f1d0
commit b001fdb57f
3 changed files with 27 additions and 19 deletions

View File

@ -216,6 +216,7 @@ def main_processing_task(rdrama : RDramaAPIInterface, session : Session):
if can_communicate: if can_communicate:
eligible_comments = get_eligible_comments(rdrama, session) eligible_comments = get_eligible_comments(rdrama, session)
for eligible_comment in eligible_comments: for eligible_comment in eligible_comments:
begin = datetime.now()
under_post_limit = Post.get_number_of_replies(eligible_comment['post_id'], session) < ALLOWED_COMMENTS_PER_POST under_post_limit = Post.get_number_of_replies(eligible_comment['post_id'], session) < ALLOWED_COMMENTS_PER_POST
under_user_limit = User.get_number_of_comments(eligible_comment['author']['id'], session) < ALLOWED_COMMENTS_PER_USER_PER_DAY under_user_limit = User.get_number_of_comments(eligible_comment['author']['id'], session) < ALLOWED_COMMENTS_PER_USER_PER_DAY
has_not_replied_to_comment = Comment.get_comment(eligible_comment['id'], session) is None has_not_replied_to_comment = Comment.get_comment(eligible_comment['id'], session) is None
@ -333,6 +334,8 @@ def main_processing_task(rdrama : RDramaAPIInterface, session : Session):
Comment.create_new_comment(parent_comment_id, automeme_comment_id, session) Comment.create_new_comment(parent_comment_id, automeme_comment_id, session)
Post.increment_replies(post_id, session) Post.increment_replies(post_id, session)
User.increase_number_of_comments(user_id, session) User.increase_number_of_comments(user_id, session)
end = datetime.now()
print(end-begin)
if __name__ == "__main__": if __name__ == "__main__":
TEST_AUTH_TOKEN = "ED3eURMKP9FKBFbi-JUxo8MPGWkEihuyIlAUGtVL7xwx0NEy4Nf6J_mxWYTPgAQx1iy1X91hx7PPHyEBS79hvKVIy5DMEzOyAe9PAc5pmqSJlLGq_-ROewMwFzGrqer4" TEST_AUTH_TOKEN = "ED3eURMKP9FKBFbi-JUxo8MPGWkEihuyIlAUGtVL7xwx0NEy4Nf6J_mxWYTPgAQx1iy1X91hx7PPHyEBS79hvKVIy5DMEzOyAe9PAc5pmqSJlLGq_-ROewMwFzGrqer4"

View File

@ -88,7 +88,7 @@ class ImageText(object):
def write_text_box(self, xy, text, box_width, font_filename, def write_text_box(self, xy, text, box_width, font_filename,
font_size=11, color=(0, 0, 0), place='left', font_size=11, color=(0, 0, 0), place='left',
justify_last_line=False, stroke_color = None, stroke_size = 0): justify_last_line=False, stroke_color = None, stroke_size = 0, calculate_only = False):
x, y = xy x, y = xy
lines = [] lines = []
@ -112,41 +112,45 @@ class ImageText(object):
for index, line in enumerate(lines): for index, line in enumerate(lines):
if place == 'left': if place == 'left':
total_size = self.get_text_size(font_filename, font_size, line) total_size = self.get_text_size(font_filename, font_size, line)
self.write_text((x, height), line, font_filename, font_size, if not calculate_only:
color, stroke_color=stroke_color, stroke_size=stroke_size) self.write_text((x, height), line, font_filename, font_size,
color, stroke_color=stroke_color, stroke_size=stroke_size)
elif place == 'right': elif place == 'right':
total_size = self.get_text_size(font_filename, font_size, line) total_size = self.get_text_size(font_filename, font_size, line)
x_left = x + box_width - total_size[0] x_left = x + box_width - total_size[0]
self.write_text((x_left, height), line, font_filename, if not calculate_only:
font_size, color, stroke_color=stroke_color, stroke_size=stroke_size) self.write_text((x_left, height), line, font_filename,
font_size, color, stroke_color=stroke_color, stroke_size=stroke_size)
elif place == 'center': elif place == 'center':
total_size = self.get_text_size(font_filename, font_size, line) total_size = self.get_text_size(font_filename, font_size, line)
x_left = int(x + ((box_width - total_size[0]) / 2)) x_left = int(x + ((box_width - total_size[0]) / 2))
self.write_text((x_left, height), line, font_filename, if not calculate_only:
font_size, color, stroke_color=stroke_color, stroke_size=stroke_size) self.write_text((x_left, height), line, font_filename,
font_size, color, stroke_color=stroke_color, stroke_size=stroke_size)
elif place == 'justify': elif place == 'justify':
words = line.split() words = line.split()
if (index == len(lines) - 1 and not justify_last_line) or \ if (index == len(lines) - 1 and not justify_last_line) or len(words) == 1:
len(words) == 1: if not calculate_only:
self.write_text((x, height), line, font_filename, font_size, self.write_text((x, height), line, font_filename, font_size, color, stroke_color=stroke_color, stroke_size=stroke_size)
color, stroke_color=stroke_color, stroke_size=stroke_size) continue
continue
line_without_spaces = ''.join(words) line_without_spaces = ''.join(words)
total_size = self.get_text_size(font_filename, font_size, total_size = self.get_text_size(font_filename, font_size,
line_without_spaces, stroke_size=stroke_size) line_without_spaces, stroke_size=stroke_size)
space_width = (box_width - total_size[0]) / (len(words) - 1.0) space_width = (box_width - total_size[0]) / (len(words) - 1.0)
start_x = x start_x = x
for word in words[:-1]: for word in words[:-1]:
self.write_text((start_x, height), word, font_filename, if not calculate_only:
font_size, color, stroke_size=stroke_size) self.write_text((start_x, height), word, font_filename,
font_size, color, stroke_size=stroke_size)
word_size = self.get_text_size(font_filename, font_size, word_size = self.get_text_size(font_filename, font_size,
word, stroke_size=stroke_size) word, stroke_size=stroke_size)
start_x += word_size[0] + space_width start_x += word_size[0] + space_width
last_word_size = self.get_text_size(font_filename, font_size, last_word_size = self.get_text_size(font_filename, font_size,
words[-1], stroke_size=stroke_size) words[-1], stroke_size=stroke_size)
last_word_x = x + box_width - last_word_size[0] last_word_x = x + box_width - last_word_size[0]
self.write_text((last_word_x, height), words[-1], font_filename, if not calculate_only:
font_size, color, stroke_color=stroke_color, stroke_size=stroke_size) self.write_text((last_word_x, height), words[-1], font_filename,
font_size, color, stroke_color=stroke_color, stroke_size=stroke_size)
height += text_height height += text_height
if total_size[0] > max_x_size: if total_size[0] > max_x_size:
max_x_size = total_size[0] max_x_size = total_size[0]

View File

@ -237,7 +237,7 @@ def add_text_box(base : Image, caption : str, region_size : tuple[int, int], coo
print("Retard moment") print("Retard moment")
return return
region_x_size, region_y_size = region_size region_x_size, region_y_size = region_size
line_image = ImageText((region_x_size, region_y_size))
if color == ColorScheme.BLACK: if color == ColorScheme.BLACK:
fill_color = (0,0,0) fill_color = (0,0,0)
stroke = None stroke = None
@ -246,14 +246,15 @@ def add_text_box(base : Image, caption : str, region_size : tuple[int, int], coo
fill_color = (255,255,255) fill_color = (255,255,255)
stroke = (0,0,0) stroke = (0,0,0)
stroke_size = 3 stroke_size = 3
line_image = ImageText((region_x_size+stroke_size, region_y_size))
place = "left" place = "left"
if "ch" in align: if "ch" in align:
place = "center" place = "center"
actual_text_box_size = line_image.write_text_box((stroke_size,0), caption, region_x_size, font_size=init_font_size, font_filename=font, color=fill_color, stroke_color=stroke, stroke_size=stroke_size, place=place) actual_text_box_size = line_image.write_text_box((stroke_size,0), caption, region_x_size, font_size=init_font_size, font_filename=font, color=fill_color, stroke_color=stroke, stroke_size=stroke_size, place=place, calculate_only=True)
_, actual_text_box_y_size, input_text_block_x_size, actual_text_box_x_size = actual_text_box_size _, actual_text_box_y_size, input_text_block_x_size, actual_text_box_x_size = actual_text_box_size
if actual_text_box_y_size <= region_y_size: if actual_text_box_y_size <= region_y_size:
line_image.write_text_box((stroke_size,0), caption, region_x_size, font_size=init_font_size, font_filename=font, color=fill_color, stroke_color=stroke, stroke_size=stroke_size, place=place)
actual_paste_x_coordinates, actual_paste_y_coordinates = coordinates actual_paste_x_coordinates, actual_paste_y_coordinates = coordinates
if align != "": if align != "":
y_difference = region_y_size - actual_text_box_y_size y_difference = region_y_size - actual_text_box_y_size