Fix bug in tag list adding, the tags were not correctly being added
Browse files- add_post.py +35 -5
add_post.py
CHANGED
@@ -45,9 +45,9 @@ def add_post_if_not_exist(post_string):
|
|
45 |
else:
|
46 |
return
|
47 |
# prepare tags first
|
48 |
-
for keys in ["tag_string_general, tag_string_artist, tag_string_character, tag_string_meta", "tag_string", "tag_string_copyright"]:
|
49 |
if keys not in post_data:
|
50 |
-
|
51 |
values = post_data[keys]
|
52 |
if not values:
|
53 |
continue
|
@@ -78,7 +78,7 @@ def add_post_if_not_exist(post_string):
|
|
78 |
tag_list_character=post_data.get('tag_list_character', []),
|
79 |
tag_list_meta=post_data.get('tag_list_meta', []),
|
80 |
tag_list=post_data.get('tag_list', []),
|
81 |
-
tag_list_copyright=post_data.get('
|
82 |
tag_count_general=post_data.get('tag_count_general', 0),
|
83 |
tag_count_artist=post_data.get('tag_count_artist', 0),
|
84 |
tag_count_character=post_data.get('tag_count_character', 0),
|
@@ -104,9 +104,37 @@ def add_post_if_not_exist(post_string):
|
|
104 |
large_file_url=post_data.get('large_file_url', ""),
|
105 |
preview_file_url=post_data.get('preview_file_url', "")
|
106 |
)
|
|
|
107 |
# create from dict
|
108 |
Post.create(**data)
|
109 |
-
print(f"Added post {post_id}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
def main():
|
112 |
last_post_id = Post.select().order_by(Post.id.desc()).get().id
|
@@ -123,6 +151,8 @@ def main():
|
|
123 |
raise e
|
124 |
pbar.update(1)
|
125 |
print("Done")
|
|
|
126 |
|
127 |
if __name__ == "__main__":
|
128 |
-
main()
|
|
|
|
45 |
else:
|
46 |
return
|
47 |
# prepare tags first
|
48 |
+
for keys in ["tag_string_general", "tag_string_artist", "tag_string_character", "tag_string_meta", "tag_string", "tag_string_copyright"]:
|
49 |
if keys not in post_data:
|
50 |
+
raise Exception(f"Error: {keys} not in {post_data}")
|
51 |
values = post_data[keys]
|
52 |
if not values:
|
53 |
continue
|
|
|
78 |
tag_list_character=post_data.get('tag_list_character', []),
|
79 |
tag_list_meta=post_data.get('tag_list_meta', []),
|
80 |
tag_list=post_data.get('tag_list', []),
|
81 |
+
tag_list_copyright=post_data.get('tag_list_copyright', []),
|
82 |
tag_count_general=post_data.get('tag_count_general', 0),
|
83 |
tag_count_artist=post_data.get('tag_count_artist', 0),
|
84 |
tag_count_character=post_data.get('tag_count_character', 0),
|
|
|
104 |
large_file_url=post_data.get('large_file_url', ""),
|
105 |
preview_file_url=post_data.get('preview_file_url', "")
|
106 |
)
|
107 |
+
#print(data)
|
108 |
# create from dict
|
109 |
Post.create(**data)
|
110 |
+
#print(f"Added post {post_id}")
|
111 |
+
def pretty_print(post_id:int) -> str:
|
112 |
+
"""
|
113 |
+
Returns a pretty printed post
|
114 |
+
"""
|
115 |
+
post = Post.get_by_id(post_id)
|
116 |
+
def pretty_print_tag(tag):
|
117 |
+
"""
|
118 |
+
Returns a pretty printed tag
|
119 |
+
"""
|
120 |
+
return f"{tag.name}({tag.id})"
|
121 |
+
|
122 |
+
def pretty_print_tags(tags):
|
123 |
+
"""
|
124 |
+
Returns a pretty printed list of tags
|
125 |
+
"""
|
126 |
+
return ", ".join([pretty_print_tag(tag) for tag in tags])
|
127 |
+
|
128 |
+
fields = {"tag_list_general", "tag_list_artist", "tag_list_character", "tag_list_meta", "tag_list_copyright", "tag_list"}
|
129 |
+
string = ""
|
130 |
+
# start printing
|
131 |
+
string += f"Post {post_id}\n"
|
132 |
+
for field in fields:
|
133 |
+
string += f"\t{field}: {pretty_print_tags(post.__getattribute__(field))}\n"
|
134 |
+
counting_fields = {"tag_count_general", "tag_count_artist", "tag_count_character", "tag_count_meta", "tag_count"}
|
135 |
+
for field in counting_fields:
|
136 |
+
string += f"\t{field}: {post.__getattribute__(field)}\n"
|
137 |
+
return string
|
138 |
|
139 |
def main():
|
140 |
last_post_id = Post.select().order_by(Post.id.desc()).get().id
|
|
|
151 |
raise e
|
152 |
pbar.update(1)
|
153 |
print("Done")
|
154 |
+
print(pretty_print(7110347))
|
155 |
|
156 |
if __name__ == "__main__":
|
157 |
+
main()
|
158 |
+
#print(pretty_print(7110347))
|