BackEnd๐ŸŒฑ/Etc

[GitHub] README.md์— ๋ธ”๋กœ๊ทธ ์ตœ์‹  ๊ธ€ ๊ฐ€์ ธ์˜ค๊ธฐ

dkswnkk 2022. 8. 29. 22:16

README.md์— ๋ธ”๋กœ๊ทธ ์ตœ์‹  ๊ธ€ ๊ฐ€์ ธ์˜ค๊ธฐ

์œ„ ์ด๋ฏธ์ง€์™€ ๊ฐ™์ด GitHub README์— ๋‚ด ๋ธ”๋กœ๊ทธ ์ตœ์‹  ๊ธ€์„ ์ž๋™์œผ๋กœ ์ฃผ๊ธฐ์ ์œผ๋กœ ๊ฐ€์ ธ์˜ค๊ณ  README์— ์ž‘์„ฑ๋˜๋„๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. (ํ‹ฐ์Šคํ† ๋ฆฌ ๊ธฐ์ค€)

๊ณผ์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  1. Python์œผ๋กœ ๋ธ”๋กœ๊ทธ ํ”ผ๋“œ(RSS) ํฌ๋กค๋ง
  2. 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 ํ˜•ํƒœ๋กœ ์ž˜ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

SSL ์˜ค๋ฅ˜

๋งŒ์•ฝ ์œ„์™€ ๊ฐ™์ด 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 ์ƒ์„ฑ

Actions ํด๋ฆญ
set up a workflow yourself ํด๋ฆญ
main.yml ์ž‘์„ฑ

๊ธฐ์กด์— ๋ฏธ๋ฆฌ ์ž‘์„ฑ๋˜์–ด ์žˆ๋˜ ์ฝ”๋“œ๋ฅผ ์ง€์šฐ๊ณ  ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ ๋„ฃ๊ณ  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

 


 

๊ฒฐ๊ณผ ํ™•์ธ