from db import * # view 6719955 post def pretty_print(post_id:int) -> str: """ Returns a pretty printed post """ post = Post.get_by_id(post_id) def pretty_print_tag(tag): """ Returns a pretty printed tag """ return f"{tag.name}({tag.id})" def pretty_print_tags(tags): """ Returns a pretty printed list of tags """ return ", ".join([pretty_print_tag(tag) for tag in tags]) fields = {"tag_list_general", "tag_list_artist", "tag_list_character", "tag_list_meta", "tag_list_copyright"} string = "" # start printing string += f"Post {post_id}\n" for field in fields: string += f"\t{field}: {pretty_print_tags(post.__getattribute__(field))}\n" return string diff = {"tag_list_general": ["virtual_youtuber"], "tag_list_character": ["otonose_kanade"], "tag_list_artist": ["jb_jagbung"], "tag_list_copyright": ["hololive", "hololive_dev_is"]} def get_ids_of_tags_from_difference(difference): """ Returns a list of ids of tags from the difference """ ids = dict() for tag_list in difference.values(): for tag in tag_list: ids[tag] = Tag.get(Tag.name == tag).id return ids def pretty_print_tags_from_difference(difference): """ Returns a pretty printed string of tags from the difference """ target_ids = get_ids_of_tags_from_difference(difference) string = "" for tag in target_ids: string += f"{tag}({target_ids[tag]})\n" return string def main(): print(pretty_print(6719955)) print(pretty_print_tags_from_difference(diff)) if __name__ == '__main__': main()