{"id":1047,"date":"2025-05-10T11:34:51","date_gmt":"2025-05-10T02:34:51","guid":{"rendered":"https:\/\/qer.kr\/?p=1047"},"modified":"2025-05-10T11:40:13","modified_gmt":"2025-05-10T02:40:13","slug":"word-py","status":"publish","type":"post","link":"https:\/\/qer.kr\/?p=1047","title":{"rendered":"word.py"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import requests\nfrom bs4 import BeautifulSoup\n\n# \u2705 \uc6cc\ub4dc\ud504\ub808\uc2a4 \uac8c\uc2dc\ubb3c \uc8fc\uc18c\nurl = \"https:\/\/qer.kr\/?p=1031\"\nres = requests.get(url)\nsoup = BeautifulSoup(res.text, \"html.parser\")\n\n# \u2705 \uac8c\uc2dc\ubb3c \uc81c\ubaa9 \ucd94\ucd9c\ntitle_tag = soup.select_one(\"h1.entry-title, h1.post-title\")\npage_title = title_tag.get_text(strip=True) if title_tag else \"\uc6a9\uc0b0\ucd08 \ubc14\ub85c\uac00\uae30 &amp; \uba54\ubaa8\"\n\n# \u2705 \ubcf8\ubb38 \ucd94\ucd9c\npost_div = soup.select_one(\"div.post-content, div.entry-content\")\nlines = &#91;]\n\nif post_div:\n    for br in post_div.find_all(\"br\"):\n        br.replace_with(\"\\n\")\n    raw_text = post_div.get_text()\n    split_lines = raw_text.split(\"\\n\")\n    for line in split_lines:\n        line = line.strip()\n        if line:\n            lines.append(line)\n\n# \u2705 \ud56d\ubaa9 \ubd84\ub9ac \ubc0f \uc21c\uc11c \uc800\uc7a5\nitems = &#91;]\nfor line in lines:\n    if line.startswith(\"@\ub9c1\ud06c:\") and \"|\" in line:\n        content = line.split(\"@\ub9c1\ud06c:\", 1)&#91;1]\n        title, link = &#91;x.strip() for x in content.split(\"|\", 1)]\n        items.append((\"link\", title, link))\n    elif line.startswith(\"@\uba54\ubaa8:\") and \"|\" in line:\n        content = line.split(\"@\uba54\ubaa8:\", 1)&#91;1]\n        title, note = &#91;x.strip() for x in content.split(\"|\", 1)]\n        items.append((\"memo\", title, note))\n    elif line.strip() == \"@\uae09\uc2dd\":\n        items.append((\"lunch\",))\n\n# \u2705 HTML \uc0dd\uc131\nhtml = f\"\"\"&lt;!DOCTYPE html&gt;\n&lt;html lang=\"ko\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;title&gt;{page_title}&lt;\/title&gt;\n  &lt;style&gt;\n    body {{\n      font-family: 'Noto Sans KR', sans-serif;\n      margin: 0;\n      padding: 0;\n      background-color: #f8f8f8;\n      color: #333;\n    }}\n    .container {{\n      max-width: 480px;\n      margin: 0 auto;\n      padding: 20px;\n    }}\n    h1 {{\n      font-size: 22px;\n      text-align: center;\n      margin-bottom: 30px;\n      color: #333;\n    }}\n    .item {{\n      margin-bottom: 14px;\n    }}\n    .link-button {{\n      display: block;\n      padding: 14px;\n      text-align: center;\n      background-color: #222;\n      color: #fff;\n      text-decoration: none;\n      border-radius: 8px;\n      font-size: 16px;\n      transition: background-color 0.2s;\n    }}\n    .link-button:hover {{\n      background-color: #444;\n    }}\n    .memo-box {{\n      background: #fff;\n      border-left: 4px solid #007acc;\n      padding: 12px 16px;\n      border-radius: 6px;\n      box-shadow: 0 1px 4px rgba(0,0,0,0.05);\n      font-size: 14px;\n      line-height: 1.5;\n      word-break: keep-all;\n      white-space: normal;\n    }}\n    .memo-title {{\n      font-weight: bold;\n      margin-bottom: 4px;\n    }}\n    iframe {{\n      width: 100%;\n      height: 250px;\n      border: none;\n      border-radius: 8px;\n      box-shadow: 0 1px 4px rgba(0,0,0,0.1);\n    }}\n  &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=\"container\"&gt;\n    &lt;h1&gt;\ud83d\udccc {page_title}&lt;\/h1&gt;\n\"\"\"\n\nfor item in items:\n    if item&#91;0] == \"link\":\n        _, title, link = item\n        html += f'&lt;div class=\"item\"&gt;&lt;a class=\"link-button\" href=\"{link}\" target=\"_blank\"&gt;{title}&lt;\/a&gt;&lt;\/div&gt;\\n'\n    elif item&#91;0] == \"memo\":\n        _, title, note = item\n        html += f'&lt;div class=\"item\"&gt;&lt;div class=\"memo-box\"&gt;&lt;div class=\"memo-title\"&gt;{title}&lt;\/div&gt;{note}&lt;\/div&gt;&lt;\/div&gt;\\n'\n    elif item&#91;0] == \"lunch\":\n        html += '&lt;div class=\"item\"&gt;&lt;iframe src=\"https:\/\/qer.kr\/lunch.html\"&gt;&lt;\/iframe&gt;&lt;\/div&gt;\\n'\n\nhtml += \"\"\"\n  &lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n\"\"\"\n\n# \u2705 \uc800\uc7a5 \uacbd\ub85c\nwith open(\"\/var\/www\/html\/yong\/index.html\", \"w\", encoding=\"utf-8\") as f:\n    f.write(html)\n\nprint(\"\u2705 index.html \uc0dd\uc131 \uc644\ub8cc \u2192 \/var\/www\/html\/yong\/index.html\")\n<\/code><\/pre>\n\n\n\n<p>@\uae09\uc2dd \uc73c\ub85c \uae09\uc2dd \ucd94\uac00<\/p>\n\n\n\n<p>\ud06c\ub860\ud0ed<\/p>\n\n\n\n<p>35 8 * * 1-5 \/usr\/bin\/python3 \/var\/www\/html\/yong\/word.py<\/p>\n\n\n\n<p>\ucd94\uac00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>@\uae09\uc2dd \uc73c\ub85c \uae09\uc2dd \ucd94\uac00 \ud06c\ub860\ud0ed 35 8 * * 1-5 \/usr\/bin\/python3 \/var\/www\/html\/yong\/word.py \ucd94\uac00<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1047","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/posts\/1047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qer.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1047"}],"version-history":[{"count":3,"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/posts\/1047\/revisions"}],"predecessor-version":[{"id":1051,"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/posts\/1047\/revisions\/1051"}],"wp:attachment":[{"href":"https:\/\/qer.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qer.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qer.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}