File size: 21,194 Bytes
aa34b1f
b90a3da
b9ed792
9194514
aa34b1f
 
 
c50d4fc
6415f78
 
aa34b1f
 
dff1837
 
 
aa34b1f
f9bd988
aa34b1f
14fbe6d
 
 
6415f78
14fbe6d
6415f78
 
 
14fbe6d
f9bd988
aa34b1f
 
3294248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b80eb1d
 
 
 
3294248
b80eb1d
 
 
 
 
 
3294248
 
 
22c0846
b80eb1d
 
d21fe3f
dd59982
d21fe3f
 
22c0846
3294248
 
 
b80eb1d
3294248
 
22c0846
d21fe3f
22c0846
d21fe3f
b80eb1d
d21fe3f
22c0846
aa34b1f
e73bcbd
aa34b1f
14fbe6d
4091161
aa34b1f
244ca67
14fbe6d
3294248
 
 
244ca67
 
 
e73bcbd
aa34b1f
1a5b0c0
b9ed792
dcc513f
2713c62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6415f78
2713c62
dcc513f
dd59982
 
dcc513f
 
2713c62
 
dcc513f
 
2713c62
 
dcc513f
2713c62
aa34b1f
 
14fbe6d
aa34b1f
 
db9b48e
6415f78
14fbe6d
244ca67
 
 
38f470f
 
 
aa30616
ea7c078
aa30616
aa34b1f
 
 
 
 
 
 
1285c5d
aa34b1f
 
 
 
dfaac2c
 
b9ed792
aa34b1f
dfaac2c
 
 
aa34b1f
 
 
 
 
 
 
 
 
72c7a0a
aa34b1f
b90a3da
 
 
1285c5d
72c7a0a
 
 
 
 
 
 
 
 
 
14fbe6d
1a5b0c0
1fdb912
 
 
6415f78
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import os
import html
import re
import time
import requests
import dotenv
import mistune
from gradio_client import Client 
from image import fetch_image

dotenv.load_dotenv()
access_key = os.getenv('ACCESS_KEY')
client_id = os.getenv('CLIENT_ID')
client_secret = os.getenv('CLIENT_SECRET')
refresh_token = os.getenv('REFRESH_TOKEN')
blog_id = os.getenv('BLOG_ID')
imgbb_api_key = os.getenv('IMGBB_API_KEY')

def generate_post_html(doi, title, category, summary, mindmap, citation):
    doi = doi.split("https://")[-1]
    print(f"Generating post for {doi}")
    title = title.replace("{", r'{').replace("}", r'}')
    title = re.sub(r"\\(?![a-zA-Z])", r"", title)
    summary = summary.replace("{", r'{').replace("}", r'}')
    mindmap = mindmap.replace("{", r'{').replace("}", r'}')
    citation = citation.replace("{", r'{').replace("}", r'}')
    citation = mistune.html(citation.replace("&", "&").strip())
    image = fetch_image(title, summary, imgbb_api_key)
    html_summary = mistune.html(summary)
    post = f"""
    <div id="paper_post">
        <script>
            window.markmap = {{
                autoLoader: {{
                    toolbar: true,
                }},
            }};
        </script>
        <script src="https://cdn.jsdelivr.net/npm/markmap-autoloader@latest"></script>
        <script>
            window.addEventListener('load', function() {{
                setTimeout(function() {{
                    const element = document.querySelector('div.mm-toolbar-item[title="Fit window size"]');
                    console.log(element);
                    if (element) {{
                        element.click();
                    }} else {{
                        console.log('Element not found');
                    }}
                }}, 0);
            }});
        </script>
        <script>
            window.addEventListener('load', function() {{
                const anchor = document.querySelector('a.mm-toolbar-brand');
                if (anchor) {{
                    anchor.href = '/';
                    const img = anchor.querySelector('img');
                    if (img) {{
                        img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABHNCSVQICAgIfAhkiAAAFe1JREFUaIF9mtmvZMlx3n8RmWepU8vde+/pWTkiKVHUiIL0YgmSYcCA7P/WDwZswaQNGRRNmZIoixouMz29375brWfLJfxQt0laIp2Fesk6hRPrlxFfpPD/WYLipHAYRWTIwPjutyN/yof1t49P9aOPJpy8P7HThwu5eza1kyPNbhFymMYUKjPFqx+86s40rHd2ebOyNxetXr8cZfn00r78xRfDj65v4uWvv7r0VIoQkoVk5N8qo/9togNiZIs2JJDk8DgpnJOiKmmaM/nwzizdeziheTT17v7c57PDYjicunZRiJtmjRMjFSCo+EB2k2hxUkWbFKlo1qlu2jibjfHO4V338Usz93a0rk0WhmhhjIxg9k4eETDDfrOk/+/G3u6GaSZl2P/rUO9yWr5378g/+LTh+ONpPn1varOzealHhw3zo1k5O2qm9XwynVSlK11phffJqRNydikMLnQ9YzsM3WZo+2XbbpfbcbPsh5utbS62cvOsteXPbsKrn74dnr25sfNfiqQ4FSRn0r9S4jd4QLh9ML3bOXD33OPiG/c/nHz7O4/KT/9szp0/luw+EO0W88XanZ22nB1HOZgHa2Zb1zRKM0XqxvAexkFYL8VWN7Dbauo6L8vN1G6WM9brOoUwXYfsv1ymq++/0s+/V+Uf/dCivFnmNwmwTErC/vNbFRAcYBhZ3ll9rsfutHh89171O58+Kj/97En54Xfuu3t/eODnn2gdKY4KTh8q9x+UHB2PVHXGl5lJnWnmwExADXaJg/NA00S2K+fjUHB3dLStZ3VVsr5cNOubxb0qHp5639wrZ7MPF+ns7172n//zZXj+dpOvkmEYJoIaCMbevu6dAg7PryeLw/Ok+t27vzP5N9/5oP6jvzwtHv+HuSs/m1btvfnhjR4/WnPv45H3PoF77ysHZ55yXuEnBUXlcBVQuP0rRui7yDgEYo4U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fNailUP1oiJgAAAABJRU5ErkJggg==';
                        img.alt = 'ReXplore';
                    }}
                    const span = anchor.querySelector('span');
                    if (span) {{
                        span.textContent = 'ReXplore';
                    }}
                }} else {{
                    console.log('Anchor element not found');
                }}
            }});
        </script>
        <style>
            .markmap {{
                position: relative;
            }}

            .markmap > svg {{
                width: 100%;
                border: 2px solid #000;
                height: 80dvh;
            }}
        </style>
        <img style="display:block; width:100%; height:100%;" id="paper_image"
            src="{image.strip()}"
            alt="{title.strip()}">
        <br>
        <b>{{getToc}} $title={{Table of Contents}}</b>
        <br>
        <div id="paper_summary">
            {html_summary.replace("&amp;", "&").strip()}
        </div>
        <br>
        <h2>Mindmap</h2>
        <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>
        <div class="markmap" id="paper_mindmap">
            <script type="text/template">
                    {mindmap.replace("&amp;", "&").replace(":", "=>").strip()}
                </script>
        </div>
        <br>
        <h2>Citation</h2>
        <div id="paper_citation">
            {mistune.html(citation.replace("&amp;", "&").strip())}
        </div>
    </div>
    """
    return post, image

def create_post(doi, title, category, summary, mindmap, citation):
    post_title = title
    post_category = f"{category}"
    try:
        post_body, post_image = generate_post_html(doi, title, category, summary, mindmap, citation)
        # with open('post.html', 'w') as f:
        #     f.write(post_body)
        # exit(code=0)
    except Exception as e:
        print(f"Error generating post: {e}")
        return None, None, None, None
    return post_title, post_category, post_body, post_image

def post_post(title, category, body, image):
    title = re.sub(r"\\(?![a-zA-Z])", r"", title)
    response = None
    try:
        data = requests.post(
            url='https://oauth2.googleapis.com/token',
            data={
                'grant_type': 'refresh_token',
                'client_secret': client_secret,
                'refresh_token': refresh_token,
                'client_id': client_id,
            },
            ).json()
        url = f"https://blogger.googleapis.com/v3/blogs/{blog_id}/posts"
        headers = {
            'Authorization': f"Bearer {data['access_token']}",
            "content-type": "application/json"
        }
        post_data = {
            "kind": "blogger#post",
            "blog": {
                "id": blog_id
            },
            "images": [{
                "url": image
            }],
            "title": title,
            "content": body,
            "labels": [category, "ZZZZZZZZZ"]
        }
        response = requests.post(url, headers=headers, json=post_data).json()
        if response['status'] != 'LIVE':
            print(response)
        if response['status'] == 'LIVE':
            print(f"The post '{title}' is {response['status']}")
            return True
        else:
            print(response)
            print(f"Error posting {title}: {response}")
            return False
    except Exception as e:
        print(response)
        print(f"Error posting {title}: {e}")
        return False
    
def post_blog(doi, title, category, summary, mindmap, citation, uaccess_key, wait_time=5):
    if uaccess_key != access_key:
        return False
    else:
        status = True
        post_title, post_category, post_body, post_image = create_post(doi, title, category, summary, mindmap, citation)
        if not all([post_title, post_category, post_body, post_image]):
            print(f'Failed to create post {post_title}')
            return False
        post_title = post_title.replace("&amp;", "&")
        if "&amp;" in post_title:
            return False
        status = post_post(post_title, post_category, post_body, post_image)
        print(f"Waiting for {wait_time*60} seconds...")
        time.sleep(wait_time*60)
        if status:
            print('Post created successfully')
            return True
        else:
            print('Failed to create post')
            return False
    
def test(uaccess_key):
    data = {
            "status": "success",
            "Astrophysics": {
                "2412.16344": {
                    "id": "2412.20276",
                    "doi": "https://doi.org/10.48550/arXiv.2412.20276",
                    "title": "From Painlev\xe9 equations to ${\cal N}=2$ susy gauge theories: prolegomena TDI-$\\infty$",
                    "category": "Astrophysics",
                    "citation": "Nair, D. G., Nagar, N. M., Ramakrishnan, V., Wielgus, M., Arratia, V., Krichbaum, T. P., Zhang, X. A., Ricarte, A., S., S., Hernández-Yévenes, J., Ford, N. M., Bandyopadhyay, B., Gurwell, M., Burridge, R., Pesce, D. W., Doeleman, S. S., Kim, J.-Y., Kim, D., Janssen, M., … Zensus, J. A. (2024). Demographics of black holes at $&lt;$100 R$_{\\rm g}$ scales: accretion flows, jets, and shadows (Version 1). arXiv. https://doi.org/10.48550/ARXIV.2412.20276",
                    "summary": "## Summary\nThe Event Horizon Telescope (EHT) has imaged supermassive black holes (SMBHs) in M87 and Sgr A*, testing General Relativity and constraining black hole mass. The EHT has also imaged inner jets of several SMBHs, but at coarser resolutions than 100 Rg. The \"Event Horizon and Environs\" (ETHER) sample is a comprehensive database of SMBH mass estimates, radio to hard X-ray flux densities, and spectral energy distribution information.\n\n## Highlights\n- The EHT has imaged SMBH shadows in M87 and Sgr A*, testing General Relativity and constraining black hole mass.\n- The EHT has imaged the inner jets of several SMBHs, but at coarser resolutions than 100 Rg.\n- The ETHER sample is a comprehensive database of SMBH mass estimates, radio to hard X-ray flux densities, and spectral energy distribution information.\n- The ETHER database includes predictions for the 230 GHz and 345 GHz flux densities in the EHT field of view for approximately 40,000 SMBHs.\n- The 43 GHz VLBA is the highest frequency sensitive phase-referenced VLBI network, providing valuable constraints for SED modeling.\n- The ngEHT is expected to measure approximately 50 SMBH masses, 30 SMBH spins, and 7 SMBH shadows.\n- The ngEHT will enable demographic studies of SMBHs, testing General Relativity and constraining black hole mass.\n\n## Key Insights\n- The EHT's ability to image SMBH shadows and inner jets has opened a new window into understanding these enigmatic objects, allowing for tests of General Relativity and constraints on black hole mass.\n- The ETHER sample provides a comprehensive database for identifying and optimizing target selection for the EHT and its upgrades, enabling the identification of a \"Gold Sample\" of nearby low-luminosity Active Galactic Nuclei (AGNs) optimal for studying jet bases and potentially imaging black hole shadows.\n- The ngEHT will enable the measurement of approximately 50 SMBH masses, 30 SMBH spins, and 7 SMBH shadows, providing a significant increase in the number of SMBHs that can be studied in detail.\n- The 43 GHz VLBA provides valuable constraints for SED modeling, allowing for the prediction of EHT flux densities and the identification of optimal targets for EHT observations.\n- The ETHER database includes predictions for the 230 GHz and 345 GHz flux densities in the EHT field of view for approximately 40,000 SMBHs, enabling the identification of potential targets for EHT observations.\n- The ngEHT will enable demographic studies of SMBHs, testing General Relativity and constraining black hole mass, and providing insights into the properties of these enigmatic objects.\n- The EHT's ability to image SMBH shadows and inner jets has significant implications for our understanding of these objects and the role they play in the universe, and will continue to be an important area of research in the coming years.",
                    "mindmap": "## Introduction\n- Event Horizon Telescope (EHT) project introduced\n- Studies black holes with high angular resolution\n- Provides insights into black hole physics\n\n## Black Hole Demographics\n- ETHER database for black hole demographics\n- Contains 3.15 million SMBH mass estimates\n- 20,000 VLBI radio flux densities included\n\n## EHT and ngEHT Capabilities\n- EHT resolves SMBH shadows at 10 Rg scale\n- ngEHT expected to improve imaging capabilities\n- Will study SMBHs with higher angular resolution\n\n## Observational Programs\n- 43 GHz VLBA imaging of ETHER targets\n- 230 GHz EHT+ALMA observations planned\n- GMVA+ALMA observations for deep imaging\n\n## Scientific Goals\n- Study jet launching and accretion flows\n- Investigate black hole physics and GR\n- Measure SMBH masses and spins\n\n## Future Prospects\n- ngEHT will improve imaging capabilities\n- Will enable study of more SMBHs\n- Provide insights into black hole physics\n\n## Collaboration and Funding\n- EHT collaboration for research and development\n- Funding agencies supporting the project\n- International collaboration for astronomy research\n\n## Research and Development\n- Developing new imaging techniques\n- Improving telescope sensitivity and resolution\n- Enhancing data analysis and modeling capabilities\n\n## Challenges and Limitations\n- Overcoming technical challenges and limitations\n- Addressing observational and theoretical uncertainties\n- Improving data quality and interpretation\n\n## Conclusion\n- EHT and ngEHT for black hole research\n- Studying SMBH demographics and physics\n- Advancing our understanding of the universe"
                }
            }
        }
    if data['status'] != 'success':
        print('Failed to fetch data')
    else:
        for category, catdata in data.items():
            if category != 'status':
                for paper_id, paperdata in catdata.items():
                    title = paperdata['title']
                    category = paperdata['category']
                    summary = paperdata.get('summary', '')
                    mindmap = paperdata.get('mindmap', '')
                    citation = paperdata.get('citation', '')
                    uaccess_key = access_key
                    try:
                        escaped_title = repr(title.encode('latin1').decode('unicode-escape')).strip()
                    except:
                        escaped_title = repr(title).strip()
                    title = html.escape(str(escaped_title).strip()[1:-1])
                    try:
                        encoded_bytes = citation.encode('latin1').decode('utf-8', errors='replace')
                    except:
                        encoded_bytes = repr(citation)
                    citation = html.unescape(encoded_bytes)
                    status = post_blog("2412.20276", title, category, summary, mindmap, citation, uaccess_key, 0)
                    print(status)
                    return status
                
if __name__ == '__main__':
    test(access_key)