| 69 | |
| 70 | |
| 71 | def json2table(json): |
| 72 | style = """ |
| 73 | <style type="text/css"> |
| 74 | .tg {border-collapse:collapse;border-spacing:0;} |
| 75 | .tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px; |
| 76 | overflow:hidden;padding:10px 5px;word-break:normal;} |
| 77 | .tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px; |
| 78 | font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;} |
| 79 | .tg .tg-0lax{text-align:left;vertical-align:top} |
| 80 | </style>""" |
| 81 | |
| 82 | html = """ |
| 83 | <table class="tg"> |
| 84 | <thead> |
| 85 | <tr> |
| 86 | <th class="tg-0lax">key</th> |
| 87 | <th class="tg-0lax">value</th> |
| 88 | </tr> |
| 89 | </thead> |
| 90 | |
| 91 | <tbody>""" |
| 92 | |
| 93 | for key, value in json.items(): |
| 94 | html += f""" |
| 95 | <tr> |
| 96 | <td class="tg-0lax">{key}</td> |
| 97 | <td class="tg-0lax">{value}<br></td> |
| 98 | </tr>""" |
| 99 | |
| 100 | html += """ |
| 101 | </tbody> |
| 102 | </table> |
| 103 | """ |
| 104 | |
| 105 | return style + html |
| 106 | |
| 107 | |
| 108 | @app.get("/show-data/", response_class=HTMLResponse) |