단축 주소

word.py

import requests
from bs4 import BeautifulSoup

# ✅ 워드프레스 게시물 주소
url = "https://qer.kr/?p=1031"
res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")

# ✅ 게시물 제목 추출
title_tag = soup.select_one("h1.entry-title, h1.post-title")
page_title = title_tag.get_text(strip=True) if title_tag else "용산초 바로가기 & 메모"

# ✅ 본문 추출
post_div = soup.select_one("div.post-content, div.entry-content")
lines = []

if post_div:
    for br in post_div.find_all("br"):
        br.replace_with("\n")
    raw_text = post_div.get_text()
    split_lines = raw_text.split("\n")
    for line in split_lines:
        line = line.strip()
        if line:
            lines.append(line)

# ✅ 항목 분리 및 순서 저장
items = []
for line in lines:
    if line.startswith("@링크:") and "|" in line:
        content = line.split("@링크:", 1)[1]
        title, link = [x.strip() for x in content.split("|", 1)]
        items.append(("link", title, link))
    elif line.startswith("@메모:") and "|" in line:
        content = line.split("@메모:", 1)[1]
        title, note = [x.strip() for x in content.split("|", 1)]
        items.append(("memo", title, note))
    elif line.strip() == "@급식":
        items.append(("lunch",))

# ✅ HTML 생성
html = f"""<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <title>{page_title}</title>
  <style>
    body {{
      font-family: 'Noto Sans KR', sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f8f8f8;
      color: #333;
    }}
    .container {{
      max-width: 480px;
      margin: 0 auto;
      padding: 20px;
    }}
    h1 {{
      font-size: 22px;
      text-align: center;
      margin-bottom: 30px;
      color: #333;
    }}
    .item {{
      margin-bottom: 14px;
    }}
    .link-button {{
      display: block;
      padding: 14px;
      text-align: center;
      background-color: #222;
      color: #fff;
      text-decoration: none;
      border-radius: 8px;
      font-size: 16px;
      transition: background-color 0.2s;
    }}
    .link-button:hover {{
      background-color: #444;
    }}
    .memo-box {{
      background: #fff;
      border-left: 4px solid #007acc;
      padding: 12px 16px;
      border-radius: 6px;
      box-shadow: 0 1px 4px rgba(0,0,0,0.05);
      font-size: 14px;
      line-height: 1.5;
      word-break: keep-all;
      white-space: normal;
    }}
    .memo-title {{
      font-weight: bold;
      margin-bottom: 4px;
    }}
    iframe {{
      width: 100%;
      height: 250px;
      border: none;
      border-radius: 8px;
      box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    }}
  </style>
</head>
<body>
  <div class="container">
    <h1>📌 {page_title}</h1>
"""

for item in items:
    if item[0] == "link":
        _, title, link = item
        html += f'<div class="item"><a class="link-button" href="{link}" target="_blank">{title}</a></div>\n'
    elif item[0] == "memo":
        _, title, note = item
        html += f'<div class="item"><div class="memo-box"><div class="memo-title">{title}</div>{note}</div></div>\n'
    elif item[0] == "lunch":
        html += '<div class="item"><iframe src="https://qer.kr/lunch.html"></iframe></div>\n'

html += """
  </div>
</body>
</html>
"""

# ✅ 저장 경로
with open("/var/www/html/yong/index.html", "w", encoding="utf-8") as f:
    f.write(html)

print("✅ index.html 생성 완료 → /var/www/html/yong/index.html")

@급식 으로 급식 추가

크론탭

35 8 * * 1-5 /usr/bin/python3 /var/www/html/yong/word.py

추가