raannakasturi commited on
Commit
1fdb912
·
1 Parent(s): 5b507dc

Refactor generate_post_html to be asynchronous and update image generation call

Browse files
Files changed (1) hide show
  1. post_blog.py +38 -41
post_blog.py CHANGED
@@ -40,12 +40,12 @@ def generate_image(title, summary, category):
40
  return f"data:image/png;base64,{image}"
41
  return image_url
42
 
43
- def generate_post_html(title, summary, mindmap, category, citation):
44
  title = title.replace("{", r"{{").replace("}", r"}}")
45
  summary = summary.replace("{", r"{{").replace("}", r"}}")
46
  mindmap = mindmap.replace("{", r"{{").replace("}", r"}}")
47
  citation = citation.replace("{", r"{{").replace("}", r"}}")
48
- image = generate_image(title, summary, category)
49
  html_summary = mistune.html(summary)
50
  post = f"""
51
  <div>
@@ -88,43 +88,37 @@ def create_post(title, category, summary, mindmap, citation):
88
 
89
  def post_post(title, category, body, image):
90
  data = None
91
- try:
92
- data = requests.post(
93
- url='https://oauth2.googleapis.com/token',
94
- data={
95
- 'grant_type': 'refresh_token',
96
- 'client_secret': client_secret,
97
- 'refresh_token': refresh_token,
98
- 'client_id': client_id,
99
- },
100
- ).json()
101
- url = f"https://blogger.googleapis.com/v3/blogs/{blog_id}/posts"
102
- headers = {
103
- 'Authorization': f"Bearer {data['access_token']}",
104
- "content-type": "application/json"
105
- }
106
- post_data = {
107
- "kind": "blogger#post",
108
- "blog": {
109
- "id": blog_id
110
- },
111
- "images": [
112
- {
113
- "url": image
114
- }
115
- ],
116
- "title": title,
117
- "content": body,
118
- "labels": [category, "recent"]
119
- }
120
- data = requests.post(url, headers=headers, json=post_data).json()
121
- print(data)
122
- if data['status'] == 'LIVE':
123
- return True
124
- else:
125
- return False
126
- except Exception as e:
127
- print('An error occurred:', str(e))
128
  return False
129
 
130
  def post_blog(title, category, summary, mindmap, citation, uaccess_key):
@@ -152,7 +146,7 @@ def test(access_key):
152
  "2412.16344": {
153
  "id": "2412.16344",
154
  "doi": "https://doi.org/10.48550/arXiv.2412.16344",
155
- "title": "On the Interplay of Constraints from $B_s$, $D$, and $K$ Meson Mixing in $Z^\prime$ Models with Implications for $b\to s ν\barν$ Transitions",
156
  "category": "Astrophysics",
157
  "citation": "Grant, C. E., Bautz, M. W., Miller, E. D., Foster, R. F., LaMarr, B., Malonis, A., Prigozhin, G., Schneider, B., Leitz, C., &amp; Falcone, A. D. (2024). Focal Plane of the Arcus Probe X-Ray Spectrograph. ArXiv. https://doi.org/10.48550/ARXIV.2412.16344",
158
  "summary": "## Summary\nThe Arcus Probe mission concept provides high-resolution soft X-ray and UV spectroscopy to study the universe. The X-ray Spectrograph (XRS) uses two CCD focal planes to detect and record X-ray photons. Laboratory performance results meet observatory requirements.\n\n## Highlights\n- The Arcus Probe mission concept explores the formation and evolution of clusters, galaxies, and stars.\n- The XRS instrument includes four parallel optical channels and two detector focal plane arrays.\n- The CCDs are designed and manufactured by MIT Lincoln Laboratory (MIT/LL).\n- The XRS focal plane utilizes high heritage MIT/LL CCDs with proven technologies.\n- Laboratory testing confirms CCID-94 performance meets required spectral resolution and readout noise.\n- The Arcus mission includes two co-aligned instruments working simultaneously.\n- The XRS Instrument Control Unit (XICU) controls the activities of the XRS.\n\n## Key Insights\n- The Arcus Probe mission concept provides a significant improvement in sensitivity and resolution over previous missions, enabling breakthrough science in understanding the universe.\n- The XRS instrument's design, including the use of two CCD focal planes and four parallel optical channels, allows for high-resolution spectroscopy and efficient detection of X-ray photons.\n- The CCDs used in the XRS instrument are designed and manufactured by MIT Lincoln Laboratory (MIT/LL), which has a proven track record of producing high-quality CCDs for space missions.\n- The laboratory performance results of the CCID-94 device demonstrate that it meets the required spectral resolution and readout noise for the Arcus mission, indicating that the instrument is capable of achieving its scientific goals.\n- The XRS Instrument Control Unit (XICU) plays a crucial role in controlling the activities of the XRS, including gathering and storing data, and processing event recognition.\n- The Arcus mission's use of two co-aligned instruments working simultaneously allows for a wide range of scientific investigations, including the study of time-domain science and the physics of time-dependent phenomena.\n- The high heritage MIT/LL CCDs used in the XRS focal plane provide a reliable and efficient means of detecting X-ray photons, enabling the instrument to achieve its scientific goals.",
@@ -174,4 +168,7 @@ def test(access_key):
174
  access_key = access_key
175
  status = post_blog(title, category, summary, mindmap, citation, access_key)
176
  print(status)
177
- return status
 
 
 
 
40
  return f"data:image/png;base64,{image}"
41
  return image_url
42
 
43
+ async def generate_post_html(title, summary, mindmap, category, citation):
44
  title = title.replace("{", r"{{").replace("}", r"}}")
45
  summary = summary.replace("{", r"{{").replace("}", r"}}")
46
  mindmap = mindmap.replace("{", r"{{").replace("}", r"}}")
47
  citation = citation.replace("{", r"{{").replace("}", r"}}")
48
+ image = await generate_image(title, summary, category)
49
  html_summary = mistune.html(summary)
50
  post = f"""
51
  <div>
 
88
 
89
  def post_post(title, category, body, image):
90
  data = None
91
+ data = requests.post(
92
+ url='https://oauth2.googleapis.com/token',
93
+ data={
94
+ 'grant_type': 'refresh_token',
95
+ 'client_secret': client_secret,
96
+ 'refresh_token': refresh_token,
97
+ 'client_id': client_id,
98
+ },
99
+ ).json()
100
+ url = f"https://blogger.googleapis.com/v3/blogs/{blog_id}/posts"
101
+ headers = {
102
+ 'Authorization': f"Bearer {data['access_token']}",
103
+ "content-type": "application/json"
104
+ }
105
+ post_data = {
106
+ "kind": "blogger#post",
107
+ "blog": {
108
+ "id": blog_id
109
+ },
110
+ "images": [{
111
+ "url": image
112
+ }],
113
+ "title": title,
114
+ "content": body,
115
+ "labels": [category, "recent"]
116
+ }
117
+ data = requests.post(url, headers=headers, json=post_data).json()
118
+ print(data)
119
+ if data['status'] == 'LIVE':
120
+ return True
121
+ else:
 
 
 
 
 
 
122
  return False
123
 
124
  def post_blog(title, category, summary, mindmap, citation, uaccess_key):
 
146
  "2412.16344": {
147
  "id": "2412.16344",
148
  "doi": "https://doi.org/10.48550/arXiv.2412.16344",
149
+ "title": "On the Interplay of Constraints from $B_s$, $D$, and $K$ Meson Mixing in $Z^\\prime$ Models with Implications for $b\to s ν\barν$ Transitions",
150
  "category": "Astrophysics",
151
  "citation": "Grant, C. E., Bautz, M. W., Miller, E. D., Foster, R. F., LaMarr, B., Malonis, A., Prigozhin, G., Schneider, B., Leitz, C., &amp; Falcone, A. D. (2024). Focal Plane of the Arcus Probe X-Ray Spectrograph. ArXiv. https://doi.org/10.48550/ARXIV.2412.16344",
152
  "summary": "## Summary\nThe Arcus Probe mission concept provides high-resolution soft X-ray and UV spectroscopy to study the universe. The X-ray Spectrograph (XRS) uses two CCD focal planes to detect and record X-ray photons. Laboratory performance results meet observatory requirements.\n\n## Highlights\n- The Arcus Probe mission concept explores the formation and evolution of clusters, galaxies, and stars.\n- The XRS instrument includes four parallel optical channels and two detector focal plane arrays.\n- The CCDs are designed and manufactured by MIT Lincoln Laboratory (MIT/LL).\n- The XRS focal plane utilizes high heritage MIT/LL CCDs with proven technologies.\n- Laboratory testing confirms CCID-94 performance meets required spectral resolution and readout noise.\n- The Arcus mission includes two co-aligned instruments working simultaneously.\n- The XRS Instrument Control Unit (XICU) controls the activities of the XRS.\n\n## Key Insights\n- The Arcus Probe mission concept provides a significant improvement in sensitivity and resolution over previous missions, enabling breakthrough science in understanding the universe.\n- The XRS instrument's design, including the use of two CCD focal planes and four parallel optical channels, allows for high-resolution spectroscopy and efficient detection of X-ray photons.\n- The CCDs used in the XRS instrument are designed and manufactured by MIT Lincoln Laboratory (MIT/LL), which has a proven track record of producing high-quality CCDs for space missions.\n- The laboratory performance results of the CCID-94 device demonstrate that it meets the required spectral resolution and readout noise for the Arcus mission, indicating that the instrument is capable of achieving its scientific goals.\n- The XRS Instrument Control Unit (XICU) plays a crucial role in controlling the activities of the XRS, including gathering and storing data, and processing event recognition.\n- The Arcus mission's use of two co-aligned instruments working simultaneously allows for a wide range of scientific investigations, including the study of time-domain science and the physics of time-dependent phenomena.\n- The high heritage MIT/LL CCDs used in the XRS focal plane provide a reliable and efficient means of detecting X-ray photons, enabling the instrument to achieve its scientific goals.",
 
168
  access_key = access_key
169
  status = post_blog(title, category, summary, mindmap, citation, access_key)
170
  print(status)
171
+ return status
172
+
173
+ if __name__ == '__main__':
174
+ test(access_key)