โœจ Settings/๐Ÿ’ป Github

[Github] ๋ธ”๋กœ๊ทธ ์ตœ์‹ ๊ธ€ Github README์— ์˜ฌ๋ฆฌ๊ธฐ

Dbswnstjd 2023. 4. 14. 09:40

Github์— README ๋ธ”๋กœ๊ทธ ์ตœ์‹ ๊ธ€ ์ž๋™ํ™”ํ•˜๊ธฐ

Github์˜ README์— ๋ธ”๋กœ๊ทธ ์ตœ์‹ ๊ธ€์„ ์ž๋™์œผ๋กœ ์˜ฌ๋ ค์ฃผ๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ•  ๊ฒƒ์ด๋‹ค. 

๊ณผ์ •์ด ๋งค์šฐ ๊ฐ„๋‹จํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋น ๋ฅด๊ฒŒ README๋ฅผ ๊พธ๋ฐ€ ์ˆ˜ ์žˆ๋‹ค.

 

1. RSS ํ”ผ๋“œ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” Python ์ฝ”๋“œ ์ž‘์„ฑ

pip install feedparser

๋จผ์ € feedparser ๋ชจ๋“ˆ์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์šด๋ฐ›์•„์ค€๋‹ค. 

 

๋‚ด RSS ํ”ผ๋“œ URL ํ™•์ธ

https://dev-wnstjd.tistory.com/rss

์ž์‹ ์˜ ๋ธ”๋กœ๊ทธ URL / rss ๋ฅผ ๋ถ™์—ฌ์ฃผ๋ฉด ๋œ๋‹ค.

ํ‹ฐ์Šคํ† ๋ฆฌ ๋ธ”๋กœ๊ทธ๋Š” ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋˜๊ณ  ๊นƒํ—ˆ๋ธŒ ๋ธ”๋กœ๊ทธ๋‚˜ ๋ฒจ๋กœ๊ทธ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค. 

 

2. Python ์ฝ”๋“œ ์ž‘์„ฑ

๋จผ์ € ์ž์‹ ์˜ README ์ €์žฅ์†Œ์— main.py ํŒŒ์ผ์„ ํ•˜๋‚˜ ๋งŒ๋“ ๋‹ค. 

import feedparser
import time
URL="https://dev-wnstjd.tistory.com/rss" # URL = "๋‚ด๋ธ”๋กœ๊ทธ ์ฃผ์†Œ/rss"
RSS_FEED = feedparser.parse(URL)
MAX_POST = 5

# ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ฐ”๋€Œ์ง€ ์•Š์„ Markdown text ์ž…๋ ฅ
markdown_text = """
<div class='blog' align='left'>
  <h2> ๐Ÿ“– BLOG ๐Ÿ“– </h2>

[![Tistory's Badge](https://github-readme-tistory-card.vercel.app/api/badge?name=์ค€์„ฑ`s๋ธ”๋กœ๊ทธ&theme=kakao)](https://dev-wnstjd.tistory.com)

</div>
<hr>
<div class='tech-stack' align='left'>
  <h2> ๐Ÿ“š TECH STACK ๐Ÿ›  </h2>
  <span stye="">
  <img src="https://img.shields.io/badge/python-3776AB?style=for-the-badge&logo=python&logoColor=white">&nbsp
  <img src="https://img.shields.io/badge/node.js-339933?style=for-the-badge&logo=Node.js&logoColor=white">&nbsp
  <img src="https://img.shields.io/badge/mysql-4479A1?style=for-the-badge&logo=mysql&logoColor=white">&nbsp
  <img src="https://img.shields.io/badge/github-181717?style=for-the-badge&logo=github&logoColor=white">&nbsp
  <img src="https://img.shields.io/badge/javascript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=black">&nbsp
  <img src="https://img.shields.io/badge/amazonaws-232F3E?style=for-the-badge&logo=amazonaws&logoColor=white">&nbsp
  </span>
<hr>

## โœ… Latest Tistory Posting<div class=blog-post text-align='left'>
"""

for idx, feed in enumerate(RSS_FEED['entries']):
    if idx > MAX_POST:
        break
    else:
        feed_date = feed['published_parsed']
        markdown_text += f" - [{feed_date.tm_mon}/{feed_date.tm_mday} - {feed['title']}]({feed['link']})\n"
markdown_text +=  """
</div>
</div>
"""
print(markdown_text)
f = open("README.md", mode="w", encoding="utf-8")
f.write(markdown_text)
f.close()

๋‚˜ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ์›๋ž˜ HTML ์ด ์žˆ์—ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์•„๋ž˜์— ์ด ๋ถ€๋ถ„์„ ์ถ”๊ฐ€ํ•ด์คฌ๋‹ค. div๋กœ ๋‹ซ์•„์ฃผ์ง€ ์•Š์œผ๋ฉด ์œ„์˜ Markdown_text๊ฐ€ ์‹คํ–‰๋˜์ง€ ์•Š์•˜๋‹ค. ์™œ ๊ทธ๋Ÿฐ์ง€๋Š” ์ฐพ์•„๋ดค๋Š”๋ฐ ์•Œ ์ˆ˜ ์—†๋‹ค..

markdown_text๋Š” ์ž์‹ ์˜ ์›๋ž˜ README ํŒŒ์ผ์— ์žˆ๋˜ ์†Œ์Šค๋ฅผ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค. 

markdown_text +=  """
</div>
</div>
"""

Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•ด์ฃผ๋Š” ๊ธ€์€ ๋งŽ๊ธฐ ๋•Œ๋ฌธ์— ์ฐพ์•„๋ณด๊ธธ ๋ฐ”๋ž€๋‹ค. 

์ด๋ ‡๊ฒŒ ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ํ•œ ๊ฐ€์ง€๋งŒ ๋” ์„ค์ •ํ•ด์ฃผ๋ฉด ๋์ด๋‹ค.

 

3. Github Actions๋กœ ์ผ์ • ์‹œ๊ฐ„๋งˆ๋‹ค ์—…๋ฐ์ดํŠธ ํ•˜๋„๋ก ์„ค์ •

Github Actions์— New workflow๋ฅผ ํด๋ฆญํ•˜๊ณ  Python application configure ๋ฅผ ์„ค์ •ํ•œ๋‹ค. 

์ด๊ณณ์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌ๋ฅผ ํ•ด์„œ ๋ถ™์—ฌ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค. 

๋‚˜๋„ ๋‹ค๋ฅธ ๋ธ”๋กœ๊ทธ์—์„œ ๋ถ™์—ฌ๋„ฃ๊ธฐ๋Š” ํ–ˆ๋Š”๋ฐ ํ‘ธ์‹œ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์„œ ํ™•์ธ์„ ํ•ด๋ดค๋”๋‹ˆ cron ๋ถ€๋ถ„์—์„œ indent๋ฅผ ๋งž์ถ”์ง€ ์•Š์•„์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ๋‹ค. ์ฃผ์˜ ํ•˜๋„๋ก ํ•˜์ž.

 

# 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@v2
    - name: Set up Python 3.9
      uses: actions/setup-python@v2
      with:
        python-version: 3.9
    - 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 "wnstjd9701@naver.com"
        git config --local user.name "wnstjd9701"
        git commit -m "Update README.md"
        git push

๋งˆ์ง€๋ง‰ git config ์—๋Š” ์ž์‹ ์˜ ๊นƒํ—ˆ๋ธŒ ์ด๋ฉ”์ผ ์ฃผ์†Œ / ๊นƒํ—ˆ๋ธŒ ์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค. 

 

๊ทธ ํ›„ ์ž์‹ ์˜ README๋ฅผ ํ™•์ธํ•ด ๋ณด๋ฉด ์ž˜ ์ ์šฉ์ด ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

- Github Action์— ๋Œ€ํ•ด ๋” ์•Œ์•„๋ณด๊ธฐ

Github Action ์„ ์ ์šฉํ•˜๋‹ค๊ฐ€ python-application.yml์—์„œ syntax error๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค. ์—๋Ÿฌ๋ฅผ ํ™•์ธํ–ˆ๋”๋‹ˆ Cron ๋ถ€๋ถ„์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค. ์˜ค๋ฅ˜๊ฐ€ ์–ด๋””์„œ ์ž˜๋ชป๋œ๊ฑด์ง€ ๊ตฌ๊ธ€๋ง์„ ํ•ด๋ณด๋‹ค๊ฐ€ ์ธ๋ดํŠธ๊ฐ€ ๋งž์ง€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค. ๊ทธ ๋’ค๋กœ ๋ธ”๋กœ๊ทธ ๊ธ€์„ ์˜ฌ๋ ธ๋Š”๋ฐ ๋ฐ”๋กœ ๋ฐ˜์˜์ด ์•ˆ๋˜์„œ ์—ฌ๋Ÿฌ๊ฐ€์ง€๋ฅผ ์ฐพ์•„๋ณธ ๊ฒฐ๊ณผ Cron์˜ ์—ญํ• ์ด ๋ฐ”๋กœ ์–ผ๋งˆ์— ํ•œ๋ฒˆ์”ฉ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•  ๊ฒƒ์ธ์ง€ ์ •ํ•˜๋Š” ์ฝ”๋“œ์˜€๋‹ค. ๋‹ค๋ฅธ ๋ธ”๋กœ๊ทธ์—์„œ ๋งค์‹œ๊ฐ„ 5๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ ์ ์šฉํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๋„ฃ์—ˆ๋”๋‹ˆ ๋˜ syntax ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ด์„œ ์›๋ž˜์˜ ์‹œ๊ฐ„์„ค์ •์œผ๋กœ ๋Œ์•„์™”๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋” ์ฐพ์•„๋ณด๋‹ค๊ฐ€ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•ด์ฃผ๋Š” ์‚ฌ์ด๋ฅดํ‹€ ์ฐพ๊ฒŒ ๋˜์—ˆ๋‹ค. 

์ž์‹ ์˜ cron ์„ ๋„ฃ์œผ๋ฉด ๋ฐ”๋กœ ์ฃผ๊ธฐ๋ฅผ ์•Œ๋ ค์ค€๋‹ค. 

๋‚˜ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ๋งค์ผ 12์‹œam์— update๊ฐ€ ๋˜๋Š”๊ฒƒ์ด๋‹ค. (UTC์ด๋ฏ€๋กœ ํ•œ๊ตญ์‹œ๊ฐ„ 9์‹œ์ด๋‹ค)

์˜ค๋Š˜ ์ ์šฉํ–ˆ์œผ๋‹ˆ ๋‚ด์ผ ์˜ค์ „9์‹œ์— ํ™•์ธ์„ ํ•ด๋ณด๋„๋ก ํ•ด์•ผ๊ฒ ๋‹ค. 

https://crontab.guru/#0_0_*/1_*_* 

 

Crontab.guru - The cron schedule expression editor

 

crontab.guru

 

** ๋ณต๋ถ™ํ•˜๋‹ค๊ฐ€ ํŒŒ์ผ์ด๋ฆ„์ด ๋‹ฌ๋ผ์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋˜ ์ ๋„ ์žˆ๋‹ค..

ํ™•์ธ ์ž˜ ํ•˜๊ณ  ์‹คํ–‰ํ•˜์ž..