{"id":995,"date":"2025-05-08T14:34:28","date_gmt":"2025-05-08T05:34:28","guid":{"rendered":"https:\/\/qer.kr\/?p=995"},"modified":"2025-05-08T16:25:27","modified_gmt":"2025-05-08T07:25:27","slug":"%ed%8c%8c%ec%9d%b4%ec%8d%ac-%ec%84%a4%ec%b9%98","status":"publish","type":"post","link":"https:\/\/qer.kr\/?p=995","title":{"rendered":"\ud30c\uc774\uc36c \uc124\uce58"},"content":{"rendered":"\n<p>pip install python-wordpress-xmlrpc requests beautifulsoup4 lxml &#8211;break-system-packages<\/p>\n\n\n\n<p>\uc624\ub77c\ud074 \ud074\ub77c\uc6b0\ub4dc \uc6b0\ubd84\ud22c\uc5d0\uc11c pip\ub85c \uc124\uce58\uc2dc \uc5d0\ub7ec\ub730\ub54c.<\/p>\n\n\n\n<p>python3 -c &#8220;from wordpress_xmlrpc import Client; import bs4; import requests; print(&#8216;\u2705 OK&#8217;)&#8221;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\uc124\uce58 \ud6c4 \ud655\uc778<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>xmlrpc.php<\/p>\n\n\n\n<p>\uc6cc\ub4dc\ud504\ub808\uc2a4 \uc790\ub3d9 \ud3ec\uc2a4\ud305\uc6a9<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\uae09\uc2dd\uc6a9<\/p>\n\n\n\n<p>import requests<br>from bs4 import BeautifulSoup<\/p>\n\n\n\n<p>url = &#8220;https:\/\/school.jbedu.kr\/yongsan4u\/M010304\/&#8221;<br>res = requests.get(url)<br>soup = BeautifulSoup(res.text, &#8220;lxml&#8221;)<\/p>\n\n\n\n<p>date = soup.find(&#8220;ul&#8221;, class_=&#8221;tch-lnc-date&#8221;).get_text(strip=True)<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\uc904\ubc14\uafc8 \ucc98\ub9ac\ub41c \uae09\uc2dd \uba54\ub274 \ucd94\ucd9c<\/h1>\n\n\n\n<p>meal_items = soup.select(&#8220;dd.tch-lnc li&#8221;)<br>if meal_items:<br>data = &#8220;<br>&#8220;.join([item.get_text(strip=True) for item in meal_items])<br>else:<br>no_data = soup.find(&#8220;div&#8221;, class_=&#8221;tch-no-data&#8221;)<br>data = &#8220;\uae09\uc2dd\uc774 \uc5c6\uc2b5\ub2c8\ub2e4.&#8221; if no_data else &#8220;\uc815\ubcf4\ub97c \ubd88\ub7ec\uc624\uc9c0 \ubabb\ud588\uc2b5\ub2c8\ub2e4.&#8221;<\/p>\n\n\n\n<p>html = f&#8221;&#8221;&#8221;<br><br>\uc624\ub298\uc758 \uae09\uc2dd<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udf71 \uc624\ub298\uc758 \uae09\uc2dd<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">{date}<\/h3>\n\n\n\n<p>{data}<br>&#8220;&#8221;&#8221;<\/p>\n\n\n\n<p>with open(&#8220;\/home\/ubuntu\/www\/lunch.html&#8221;, &#8220;w&#8221;, encoding=&#8221;utf-8&#8243;) as f:<br>f.write(html)<\/p>\n\n\n\n<p>\uc6cc\ub4dc\ud504\ub808\uc2a4 \uc5c5\ub85c\ub4dc<\/p>\n\n\n\n<p>from wordpress_xmlrpc import Client, WordPressPost<br>from wordpress_xmlrpc.methods.posts import NewPost<br>import datetime<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">1. \uc6cc\ub4dc\ud504\ub808\uc2a4 \ub85c\uadf8\uc778 \uc815\ubcf4 \uc124\uc815<\/h1>\n\n\n\n<p>wp_url = &#8220;https:\/\/xmlrpc.php&#8221;<br>wp_username = &#8220;&#8221;<br>wp_password = &#8220;&#8221;<br>client = Client(wp_url, wp_username, wp_password)<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">2. HTML \ud30c\uc77c \uc77d\uae30<\/h1>\n\n\n\n<p>html_path = &#8220;\/var\/www\/html\/lunch.html&#8221;<br>with open(html_path, &#8220;r&#8221;, encoding=&#8221;utf-8&#8243;) as f:<br>html_content = f.read()<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">3. \uc624\ub298 \ub0a0\uc9dc \uac00\uc838\uc624\uae30<\/h1>\n\n\n\n<p>today = datetime.date.today().strftime(&#8220;%Y-%m-%d&#8221;)<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">4. \uc6cc\ub4dc\ud504\ub808\uc2a4 \uae00 \uc791\uc131<\/h1>\n\n\n\n<p>post = WordPressPost()<br>post.title = f&#8221;{today} \uae09\uc2dd \uc815\ubcf4&#8221;<br>post.content = html_content<br>post.post_status = &#8220;publish&#8221;<br>post.terms_names = {<br>&#8216;category&#8217;: [&#8216;\uae09\uc2dd&#8217;],<br>&#8216;post_tag&#8217;: [&#8216;\uc810\uc2ec&#8217;, &#8216;\ud559\uad50&#8217;]<br>}<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">5. \uc5c5\ub85c\ub4dc \uc2e4\ud589<\/h1>\n\n\n\n<p>client.call(NewPost(post))<br>print(&#8220;\u2705 \uc6cc\ub4dc\ud504\ub808\uc2a4\uc5d0 \uae09\uc2dd \uc815\ubcf4 \uac8c\uc2dc \uc644\ub8cc!&#8221;)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\ud06c\ub860\ud0ed<\/p>\n\n\n\n<p>crontab -e<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>30 8 * * 1-5 \/var\/www\/html\/run_lunch.sh >> \/var\/www\/html\/lunch_log.txt 2>&amp;1<\/p>\n\n\n\n<p>\uc6d4 \uae08 8:30 \uc2dc\ud589<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>pip install python-wordpress-xmlrpc requests beautifulsoup4 lxml &#8211;break-system-packages \uc624\ub77c\ud074 \ud074\ub77c\uc6b0\ub4dc \uc6b0\ubd84\ud22c\uc5d0\uc11c pip\ub85c \uc124\uce58\uc2dc \uc5d0\ub7ec\ub730\ub54c. python3 -c &#8220;from wordpress_xmlrpc import Client; import bs4; import requests; print(&#8216;\u2705 OK&#8217;)&#8221; \uc124\uce58 \ud6c4 \ud655\uc778 xmlrpc.php \uc6cc\ub4dc\ud504\ub808\uc2a4 \uc790\ub3d9 \ud3ec\uc2a4\ud305\uc6a9 \uae09\uc2dd\uc6a9 import requestsfrom bs4 import BeautifulSoup url = &#8220;https:\/\/school.jbedu.kr\/yongsan4u\/M010304\/&#8221;res = requests.get(url)soup = BeautifulSoup(res.text, &#8220;lxml&#8221;) date = soup.find(&#8220;ul&#8221;, class_=&#8221;tch-lnc-date&#8221;).get_text(strip=True) \uc904\ubc14\uafc8 \ucc98\ub9ac\ub41c \uae09\uc2dd \uba54\ub274 \ucd94\ucd9c meal_items = soup.select(&#8220;dd.tch-lnc li&#8221;)if meal_items:data = &#8220;&#8220;.join([item.get_text(strip=True) for item in meal_items])else:no_data = soup.find(&#8220;div&#8221;, class_=&#8221;tch-no-data&#8221;)data = &#8220;\uae09\uc2dd\uc774 \uc5c6\uc2b5\ub2c8\ub2e4.&#8221; if no_data else &#8220;\uc815\ubcf4\ub97c \ubd88\ub7ec\uc624\uc9c0 \ubabb\ud588\uc2b5\ub2c8\ub2e4.&#8221; html = f&#8221;&#8221;&#8221; \uc624\ub298\uc758 \uae09\uc2dd \ud83c\udf71 \uc624\ub298\uc758 \uae09\uc2dd {date} {data}&#8220;&#8221;&#8221; with open(&#8220;\/home\/ubuntu\/www\/lunch.html&#8221;, &#8220;w&#8221;, encoding=&#8221;utf-8&#8243;) as f:f.write(html) \uc6cc\ub4dc\ud504\ub808\uc2a4 \uc5c5\ub85c\ub4dc from wordpress_xmlrpc import Client, WordPressPostfrom wordpress_xmlrpc.methods.posts import NewPostimport datetime 1. \uc6cc\ub4dc\ud504\ub808\uc2a4 \ub85c\uadf8\uc778 \uc815\ubcf4 \uc124\uc815 wp_url = &#8220;https:\/\/xmlrpc.php&#8221;wp_username = &#8220;&#8221;wp_password = &#8220;&#8221;client = Client(wp_url, wp_username, wp_password) 2. HTML \ud30c\uc77c \uc77d\uae30 html_path = &#8220;\/var\/www\/html\/lunch.html&#8221;with open(html_path, &#8220;r&#8221;, encoding=&#8221;utf-8&#8243;) as f:html_content = f.read() 3. \uc624\ub298 \ub0a0\uc9dc \uac00\uc838\uc624\uae30 today = datetime.date.today().strftime(&#8220;%Y-%m-%d&#8221;) 4. \uc6cc\ub4dc\ud504\ub808\uc2a4 \uae00 \uc791\uc131 post = WordPressPost()post.title = f&#8221;{today} \uae09\uc2dd \uc815\ubcf4&#8221;post.content = html_contentpost.post_status = &#8220;publish&#8221;post.terms_names = {&#8216;category&#8217;: [&#8216;\uae09\uc2dd&#8217;],&#8216;post_tag&#8217;: [&#8216;\uc810\uc2ec&#8217;, &#8216;\ud559\uad50&#8217;]} 5. \uc5c5\ub85c\ub4dc \uc2e4\ud589 client.call(NewPost(post))print(&#8220;\u2705 \uc6cc\ub4dc\ud504\ub808\uc2a4\uc5d0 \uae09\uc2dd \uc815\ubcf4 \uac8c\uc2dc \uc644\ub8cc!&#8221;) \ud06c\ub860\ud0ed crontab -e 30 8 * * 1-5 \/var\/www\/html\/run_lunch.sh >> \/var\/www\/html\/lunch_log.txt 2>&amp;1 \uc6d4 \uae08 8:30 \uc2dc\ud589<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-995","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/posts\/995","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=995"}],"version-history":[{"count":5,"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/posts\/995\/revisions"}],"predecessor-version":[{"id":1009,"href":"https:\/\/qer.kr\/index.php?rest_route=\/wp\/v2\/posts\/995\/revisions\/1009"}],"wp:attachment":[{"href":"https:\/\/qer.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qer.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qer.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}