Spaces:
Running
Running
Commit
·
244ca67
1
Parent(s):
1285c5d
Add error handling and user notification for post generation in post_blog.py
Browse files- post_blog.py +9 -1
post_blog.py
CHANGED
@@ -41,6 +41,7 @@ def generate_post_html(title, summary, mindmap, citation):
|
|
41 |
<p id="paper_summary">{html_summary.replace("&", "&")}</p>
|
42 |
</br>
|
43 |
<h2>Mindmap</h2>
|
|
|
44 |
<div class="markmap" id="paper_mindmap">
|
45 |
<script type="text/template">
|
46 |
{mindmap.replace("&", "&").replace(":", "=>")}
|
@@ -58,7 +59,11 @@ def generate_post_html(title, summary, mindmap, citation):
|
|
58 |
def create_post(title, category, summary, mindmap, citation):
|
59 |
post_title = title
|
60 |
post_category = f"{category}"
|
61 |
-
|
|
|
|
|
|
|
|
|
62 |
return post_title, post_category, post_body, post_image
|
63 |
|
64 |
def post_post(title, category, body, image):
|
@@ -107,6 +112,9 @@ def post_blog(title, category, summary, mindmap, citation, uaccess_key, wait_tim
|
|
107 |
else:
|
108 |
status = True
|
109 |
post_title, post_category, post_body, post_image = create_post(title, category, summary, mindmap, citation)
|
|
|
|
|
|
|
110 |
status = post_post(post_title, post_category, post_body, post_image)
|
111 |
print(f"Waiting for {wait_time*60} seconds...")
|
112 |
time.sleep(wait_time*60)
|
|
|
41 |
<p id="paper_summary">{html_summary.replace("&", "&")}</p>
|
42 |
</br>
|
43 |
<h2>Mindmap</h2>
|
44 |
+
<p><small><em>If MindMap doesn't load, please refresh the page.</em></small></p>
|
45 |
<div class="markmap" id="paper_mindmap">
|
46 |
<script type="text/template">
|
47 |
{mindmap.replace("&", "&").replace(":", "=>")}
|
|
|
59 |
def create_post(title, category, summary, mindmap, citation):
|
60 |
post_title = title
|
61 |
post_category = f"{category}"
|
62 |
+
try:
|
63 |
+
post_body, post_image = generate_post_html(title, summary, mindmap, citation)
|
64 |
+
except Exception as e:
|
65 |
+
print(f"Error generating post: {e}")
|
66 |
+
return None, None, None, None
|
67 |
return post_title, post_category, post_body, post_image
|
68 |
|
69 |
def post_post(title, category, body, image):
|
|
|
112 |
else:
|
113 |
status = True
|
114 |
post_title, post_category, post_body, post_image = create_post(title, category, summary, mindmap, citation)
|
115 |
+
if not all([post_title, post_category, post_body, post_image]):
|
116 |
+
print(f'Failed to create post {post_title}')
|
117 |
+
return False
|
118 |
status = post_post(post_title, post_category, post_body, post_image)
|
119 |
print(f"Waiting for {wait_time*60} seconds...")
|
120 |
time.sleep(wait_time*60)
|