raannakasturi commited on
Commit
aea389a
·
2 Parent(s): c50d4fc dd59982

Merge branch 'main' of https://huggingface.co/spaces/raannakasturi/ReXploreBackend

Browse files
Files changed (1) hide show
  1. post_blog.py +15 -38
post_blog.py CHANGED
@@ -33,25 +33,8 @@ def generate_post_html(title, summary, mindmap, citation):
33
  html_summary = mistune.html(summary)
34
  post = f"""
35
  <div id="paper_post">
36
- <script src="https://cdn.jsdelivr.net/npm/markmap-toolbar@0.18.4/dist/index.min.js"></script>
37
- <script src="https://cdn.jsdelivr.net/npm/markmap-autoloader@latest"></script>
38
- <script>
39
- window.markmap = {{
40
- autoLoader: {{
41
- toolbar: true,
42
- }},
43
- }};
44
- </script>
45
- <script>
46
- window.addEventListener(&#39;load&#39;, function() {{
47
- const element = document.querySelector(&#39;div.mm-toolbar-item[title=&quot;Fit window size&quot;]&#39;);
48
- if (element) {{
49
- element.click();
50
- }} else {{
51
- console.log(&#39;Element not found&#39;);
52
- }}
53
- }});
54
- </script>
55
  <style>
56
  .markmap {{
57
  position: relative;
@@ -62,35 +45,25 @@ def generate_post_html(title, summary, mindmap, citation):
62
  height: 80dvh;
63
  }}
64
  </style>
65
- <style>
66
- .markmap {{
67
- position: relative;
68
- }}
69
- .markmap > svg {{
70
- width: 100%;
71
- border: 2px solid #000;
72
- height: 80dvh;
73
- }}
74
- </style>
75
- <img style="display:block; width:100%; height:100%;" id="paper_image" src="{image}" alt="{title}">
76
  <br>
77
  <b>{{getToc}} $title={{Table of Contents}}</b>
78
  <br>
79
  <div id="paper_summary">
80
- {html_summary.replace("&amp;", "&")}
81
  </div>
82
  <br>
83
  <h2>Mindmap</h2>
84
  <p><small><em>If MindMap doesn't load, go to the <a href="/">Homepage</a> and visit blog again or <a href="/#">Switch to Android App (Under Development)</a>.</em></small></p>
85
  <div class="markmap" id="paper_mindmap" data-markmap-url="{svg_url}">
86
  <script type="text/template">
87
- {mindmap.replace("&amp;", "&").replace(":", "=>")}
88
  </script>
89
  </div>
90
  <br>
91
  <h2>Citation</h2>
92
  <div id="paper_citation">
93
- {mistune.html(citation.replace("&amp;", "&"))}
94
  </div>
95
  </div>
96
  """
@@ -107,7 +80,7 @@ def create_post(title, category, summary, mindmap, citation):
107
  return post_title, post_category, post_body, post_image
108
 
109
  def post_post(title, category, body, image):
110
- data = None
111
  try:
112
  data = requests.post(
113
  url='https://oauth2.googleapis.com/token',
@@ -135,14 +108,18 @@ def post_post(title, category, body, image):
135
  "content": body,
136
  "labels": [category, "ZZZZZZZZZ"]
137
  }
138
- data = requests.post(url, headers=headers, json=post_data).json()
139
- if data['status'] == 'LIVE':
140
- print(f"The post '{title}' is {data['status']}")
 
 
141
  return True
142
  else:
143
- print(f"Error posting {title}: {data}")
 
144
  return False
145
  except Exception as e:
 
146
  print(f"Error posting {title}: {e}")
147
  return False
148
 
 
33
  html_summary = mistune.html(summary)
34
  post = f"""
35
  <div id="paper_post">
36
+ <script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
37
+ <script src="https://cdn.jsdelivr.net/npm/markmap-toolbar"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  <style>
39
  .markmap {{
40
  position: relative;
 
45
  height: 80dvh;
46
  }}
47
  </style>
48
+ <img style="display:block; width:100%; height:100%;" id="paper_image" src="{image.strip()}" alt="{title.strip()}">
 
 
 
 
 
 
 
 
 
 
49
  <br>
50
  <b>{{getToc}} $title={{Table of Contents}}</b>
51
  <br>
52
  <div id="paper_summary">
53
+ {html_summary.replace("&amp;", "&").strip()}
54
  </div>
55
  <br>
56
  <h2>Mindmap</h2>
57
  <p><small><em>If MindMap doesn't load, go to the <a href="/">Homepage</a> and visit blog again or <a href="/#">Switch to Android App (Under Development)</a>.</em></small></p>
58
  <div class="markmap" id="paper_mindmap" data-markmap-url="{svg_url}">
59
  <script type="text/template">
60
+ {mindmap.replace("&amp;", "&").replace(":", "=>").strip()}
61
  </script>
62
  </div>
63
  <br>
64
  <h2>Citation</h2>
65
  <div id="paper_citation">
66
+ {mistune.html(citation.replace("&amp;", "&").strip())}
67
  </div>
68
  </div>
69
  """
 
80
  return post_title, post_category, post_body, post_image
81
 
82
  def post_post(title, category, body, image):
83
+ response = None
84
  try:
85
  data = requests.post(
86
  url='https://oauth2.googleapis.com/token',
 
108
  "content": body,
109
  "labels": [category, "ZZZZZZZZZ"]
110
  }
111
+ response = requests.post(url, headers=headers, json=post_data).json()
112
+ if response['status'] != 'LIVE':
113
+ print(response)
114
+ if response['status'] == 'LIVE':
115
+ print(f"The post '{title}' is {response['status']}")
116
  return True
117
  else:
118
+ print(response)
119
+ print(f"Error posting {title}: {response}")
120
  return False
121
  except Exception as e:
122
+ print(response)
123
  print(f"Error posting {title}: {e}")
124
  return False
125