[GitHub] README.md์ ๋ธ๋ก๊ทธ ์ต์ ๊ธ ๊ฐ์ ธ์ค๊ธฐ
์ ์ด๋ฏธ์ง์ ๊ฐ์ด GitHub README์ ๋ด ๋ธ๋ก๊ทธ ์ต์ ๊ธ์ ์๋์ผ๋ก ์ฃผ๊ธฐ์ ์ผ๋ก ๊ฐ์ ธ์ค๊ณ README์ ์์ฑ๋๋๋ก ํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ ๋ฆฌํด๋ณด๊ฒ ์ต๋๋ค. (ํฐ์คํ ๋ฆฌ ๊ธฐ์ค)
๊ณผ์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- Python์ผ๋ก ๋ธ๋ก๊ทธ ํผ๋(RSS) ํฌ๋กค๋ง
- GitHub Actions๋ฅผ ํ์ฉํ์ฌ Workflow ์์ฑ
1. RSS ํฌ๋กค๋ง ํ ์คํธ
๋จผ์ ํฐ์คํ ๋ฆฌ ํผ๋๊ฐ ์ ๋ถ๋ฌ์์ง๋์ง ํ ์คํธ๋ฅผ ์งํํฉ๋๋ค. (ํ ์คํธ์ด๋ฉฐ, ํ์๋ ์๋๋๋ค. 2๋ฒ์ผ๋ก ๋์ด๊ฐ์ ๋ ๋ฉ๋๋ค.)
import feedparser
URL="https://dkswnkk.tistory.com/rss" # URL = "๋ด๋ธ๋ก๊ทธ ์ฃผ์/rss"
RSS_FEED = feedparser.parse(URL)
print(RSS_FEED)
URL๋ถ๋ถ์ ์์ ์ ๋ธ๋ก๊ทธ ์ฃผ์๋ฅผ ๋ฃ๊ณ ๋ค์ /rss๋ฅผ ๋ถ์ฌ์ฃผ์๋ฉด ๋ฉ๋๋ค.
๊ฒฐ๊ณผ๊ฐ ์กฐ๊ธ ์ง์ ๋ถํ์ง๋ง ๋ชจ๋ ๊ฒ์๊ธ์ JSON ํํ๋ก ์ ๋ถ๋ฌ์ค๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
๋ง์ฝ ์์ ๊ฐ์ด SSLCertVerificationError ์๋ฌ๊ฐ ๋ฐ์ํ๋ค๋ฉด ์ฃผ์ https๋ฅผ http๋ก ์์ฑํ๊ณ ์คํํ๋ฉด ์ ์์ ์ผ๋ก ์ถ๋ ฅ์ด ๋ ๊ฒ์ ๋๋ค.
์ฐ๋ฆฌ๋ ์ ์๋ง์ JSON ํํ์์ 'entries' ํค ๊ฐ์ ์ฌ์ฉํ ์์ ์ ๋๋ค.
import feedparser
URL="http://dkswnkk.tistory.com/rss"
RSS_FEED = feedparser.parse(URL)
for feed in enumerate(RSS_FEED['entries']):
print(feed)
{
'title': '[๋ฐฑ์ค,c++] 16236๋ฒ - ์๊ธฐ ์์ด',
'title_detail': {
'type': 'text/plain',
'language': None,
'base': 'http://dkswnkk.tistory.com/rss',
'value': '[๋ฐฑ์ค,c++] 16236๋ฒ - ์๊ธฐ ์์ด'
},
'links': [
{
'rel': 'alternate',
'type': 'text/html',
'href': 'https://dkswnkk.tistory.com/621'
}
],
'link': 'https://dkswnkk.tistory.com/621',
'summary': '๋ด์ฉ';,
'summary_detail': {
'type': 'text/html',
'language': None,
'base': 'http://dkswnkk.tistory.com/rss',
'value': ''
},
'tags': [
{
'term': '๋ฐฑ์ค(BOJ)',
'scheme': None,
'label': None
},
{
'term': '16236',
'scheme': None,
'label': None
},
{
'term': 'BOJ',
'scheme': None,
'label': None
},
{
'term': '์๋ฎฌ๋ ์ด์
',
'scheme': None,
'label': None
},
{
'term': '์๊ธฐ ์์ด',
'scheme': None,
'label': None
}
],
'authors': [
{
'name': '์์ฃผํ'
}
],
'author': '์์ฃผํ',
'author_detail': {
'name': '์์ฃผํ'
},
'id": 'https://dkswnkk.tistory.com/621',
'guidislink': False,
'comments': 'https://dkswnkk.tistory.com/621#entry621comment',
'published': 'Sun, 28 Aug 2022 12:53:53 +0900',
'published_parsed': time.struct_time(tm_year=2022, tm_mon=8, tm_mday=28, tm_hour=3, tm_min=53, tm_sec=53, tm_wday=6, tm_yday=240, tm_isdst=0)
}
entries์ ํํ๋ ์์ฒ๋ผ ๊ตฌ์ฑ๋์ด ์์ต๋๋ค. ์ฌ๋งํ ํฌ์คํธ์ ์ ๋ณด๋ ๊ฐ์ ธ์ฌ ์ ์๋ ๊ฑธ ํ์ธํ ์ ์์ต๋๋ค.
์ ๋ ๋ณธ๋ฌธ ์ต์๋จ ์ด๋ฏธ์ง์ฒ๋ผ ์์ฑ ๋ ์ง, ์ ๋ชฉ, ๋งํฌ ์ ๋๋ง ๊ฐ์ ธ์์ ์ฌ์ฉํ๋๋ก ํ๊ฒ ์ต๋๋ค.
2. GitHub Repository์ python ํ์ผ ์์ฑ
๋ ํฌ์งํ ๋ฆฌ์ ์๋์ ์ฝ๋๊ฐ ์์ฑ๋ .py ํ์ผ์ ์์ฑํฉ๋๋ค. URL๋ถ๋ถ์ ์์ ์ ๋ธ๋ก๊ทธ ์ฃผ์๋ฅผ ๋ฃ๊ณ ๋ค์ /rss๋ฅผ ๋ถ์ฌ์ฃผ์๋ฉด ๋ฉ๋๋ค.
import feedparser, time
URL = "https://dkswnkk.tistory.com/rss"
RSS_FEED = feedparser.parse(URL)
MAX_POST = 5
markdown_text = """
## โ
Latest Blog Post
""" # list of blog posts will be appended here
for idx, feed in enumerate(RSS_FEED['entries']):
if idx > MAX_POST:
break
else:
feed_date = feed['published_parsed']
markdown_text += f"[{time.strftime('%Y/%m/%d', feed_date)} - {feed['title']}]({feed['link']}) <br/>\n"
f = open("README.md", mode="w", encoding="utf-8")
f.write(markdown_text)
f.close()
3. GitHub Actions ์์ฑ
๊ธฐ์กด์ ๋ฏธ๋ฆฌ ์์ฑ๋์ด ์๋ ์ฝ๋๋ฅผ ์ง์ฐ๊ณ ์๋์ ์ฝ๋๋ฅผ ๋ถ์ฌ ๋ฃ๊ณ Start Commit ํด๋ฆญ(์ฝ๋์ ์ด๋ฉ์ผ๊ณผ ์ ์ ๋ค์ ํ์ธ)
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: "0 0 */1 * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install feedparser
- name: Run Update Python Script
run: |
python main.py
- name: Update README.md file
run: |
git pull
git add .
git diff
git config --local user.email "๋ณธ์ธ์ ๊นํ๋ธ ์ด๋ฉ์ผ ์
๋ ฅ"
git config --local user.name "๋ณธ์ธ์ ๊นํ๋ธ ์ด๋ฆ ์
๋ ฅ"
git commit -m "Updating Blog Posts"
git push
๊ฒฐ๊ณผ ํ์ธ