如何将JSON API响应转换为HTML表?

w6lpcovy  于 2023-07-01  发布在  其他
关注(0)|答案(1)|浏览(108)

我正在尝试编写一个python脚本,它将通过JQL查询从Jira中提取票证,将其转换为HTML格式,并生成一个发布说明文档以发布到我们的知识库API。
我不是很熟悉HTML表格格式,所以希望有一个库或其他东西可以提供帮助。
JSON输出如下所示:https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-search/#api-rest-api-3-search-get
具有正确格式的文章的HTML输出如下所示:

{
    "valid": true,
    "data": {
        "id": "",
        "type": "article",
        "category": "",
        "current_version_id": "",
        "modified_author": "",
        "category_view": false,
        "content_article": null,
        "article_link": null,
        "author": "",
        "summary": "          Test Release Notes  March 17, 2022        We are glad to inform you that the latest version [versionName] has been released. Below is the list of development tickets that were part of this upgrade.        Platform           T...",
        "project_id": "",
        "name": "Test Release Notes",
        "toc_title": "",
        "internal_title": "",
        "meta_description": "",
        "meta_page_title": "",
        "version_note": "",
        "url_hash": "test-release-notes",
        "pdf": "/home/pdfexport/id/",
        "searchTitle": {
            "en": "Test Release Notes"
        },
        "internal_note": null,
        "current_version": {
            "en": {
                "title": "Test Release Notes",
                "text": "<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 14px;\"><span style=\"font-size: 28px;\"><strong><img src=\"https://arn-resources.upraise.io/93c09ad4-8e4b-398f-9795-62f5ea84ea53/10049/49471/images/arn_file_2022-04-26-16-04-59-118.jpeg\" alt=\"\" width=\"420\" class=\"fr-fic fr-dii\" style=\"width: 54%;\"></strong></span></span></p><h2>Test Release Notes</h2><h3>March 17, 2022<br><span style=\"font-family: arial, helvetica, sans-serif; font-size: 14px;\">&nbsp;<img src=\"https://arn-resources.upraise.io/93c09ad4-8e4b-398f-9795-62f5ea84ea53/10069/47796/images/arn_file_2022-01-26-19-17-43-144.png\" alt=\"\" width=\"78\" height=\"12\" class=\"fr-fic fr-dii\"></span></h3><p><span style=\"font-size: 16px; font-family: arial, helvetica, sans-serif;\">We are glad to inform you that the latest version [versionName] has been released. Below is the list of development tickets that were part of this upgrade.</span></p><p>&nbsp;</p><p><span style=\"font-size: 26px; font-family: arial, helvetica, sans-serif;\"><strong>Platform</strong></span>&nbsp;</p><p><br></p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width: 100%; margin-left: calc(0%);\" width=\"174\"><thead><tr><th style=\"width: 17.4361%;\">Ticket Number</th><th style=\"width: 82.5639%;\">Summary</th></tr></thead><tbody><tr><td height=\"21\" style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; height: 16pt; width: 17.4361%;\" width=\"50%\">TEST-1</td><td style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; width: 82.5639%;\" width=\"50%\">Test 1 Summary</td></tr><tr><td height=\"21\" style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; height: 16pt; width: 17.4361%;\">TEST-2<br></td><td style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; width: 82.5639%;\">Test 2 Summary<br></td></tr><tr><td height=\"21\" style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; height: 16pt; width: 17.4361%;\">TEST-3<br></td><td style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; width: 82.5639%;\">Test 3 Summary<br></td></tr></tbody></table><p><span style=\"font-family: arial, helvetica, sans-serif;\"><strong><span style=\"font-size: 28px;\"><img src=\"https://arn-resources.upraise.io/93c09ad4-8e4b-398f-9795-62f5ea84ea53/10069/47796/images/arn_file_2022-01-26-19-17-43-144.png\" alt=\"\" width=\"78\" height=\"12\" class=\"fr-fic fr-dii\"></span></strong></span></p><p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 26px;\"><strong>Radiology</strong></span></p><p>&nbsp;</p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width: 100%;\" width=\"174\"><thead><tr><th style=\"width: 16.9972%;\">Ticket Number</th><th style=\"width: 83.0028%;\">Summary</th></tr></thead><tbody><tr><td height=\"21\" style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; height: 16pt; width: 16.9972%;\" width=\"50%\">TEST-4<br></td><td style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; width: 83.0028%;\" width=\"50%\">Test 4 Summary<br></td></tr><tr><td height=\"21\" style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; height: 16pt; width: 16.9972%;\">TEST-5<br></td><td style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; width: 83.0028%;\">Test 5 Summary<br></td></tr><tr><td height=\"21\" style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; height: 16pt; width: 16.9972%;\">TEST-6<br></td><td style=\"color: black; font-size: 16px; font-weight: 400; font-style: normal; text-decoration: none; vertical-align: bottom; width: 83.0028%;\">Test 6 Summary<br></td></tr></tbody></table><p><br></p>"
            }
        },
        "auto_save": false,
        "redirect_options": {
            "new_tab": false,
            "redirect_url": "https://"
        },
        "api_data": null,
        "thumbnail": {
            "url": ""
        },
        "banner": {
            "url": ""
        },
        "meta_data": null,
        "view_count": null,
        "quality_views": null,
        "index": 1,
        "current_version_number": "1.00",
        "date_created": "06/22/2023 2:15 pm EDT",
        "date_modified": "06/28/2023 1:38 am EDT",
        "date_published": false,
        "date_deleted": null,
        "date_archived": null,
        "date_last_viewed": null,
        "callout_created": "06/22/2023 2:15 pm EDT",
        "scheduled_publish_date": null,
        "scheduled_archive_date": null,
        "callout_expire": 1688615940,
        "reader_roles": null,
        "inherited_roles": null,
        "related_articles": [
            ""
        ],
        "user_teams": null,
        "tags": false,
        "parents": [
            "647796ad9f64a236df45c61c",
            "64948f9386fce851eb6f05a4"
        ],
        "snippets": null,
        "files": null,
        "topic_articles": null,
        "ready_versions": null,
        "redirect_link": [
            "test-release-notes"
        ],
        "search_phrases": false,
        "application_screens": [
            ""
        ],
        "languages": null,
        "template_article": false,
        "topic_article": false,
        "external_redirect": false,
        "callout_video": null,
        "prevent_searching": "",
        "hide_from_toc": false,
        "hide_from_page": false,
        "hide_from_widgets": false,
        "remove_pdf": "",
        "remove_feedback": false,
        "remove_comments": false,
        "visibility": "public",
        "callout": "none",
        "status": "draft"
    }
}

我已经能够拉文章的格式和门票的格式和字段,我想合并。
我花了一些时间将Jira响应JSON放入pandas Dataframe 中,但我认为这有点误导。

vq8itlhq

vq8itlhq1#

我知道你需要HTML作为你的Python代码中的字符串。这通常是通过HTML渲染引擎完成的。您可以从https://wiki.python.org/moin/Templating开始
您的示例看起来足够简单,可以使用模板文章中提到的标准string.Template来解决。但重要的是,您仍然需要有人为您构建HTML表模板。
有可用的UI组件库,但我不知道它们中的任何一个对于您的应用程序来说足够简单。它们旨在构建Web应用程序。我怀疑你会发现一个只是从python dict或数组创建一个漂亮的HTML表。

相关问题