Skip to content

Commit

Permalink
feat: create github action workflow and script
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumaC committed Dec 12, 2023
1 parent f7d66f3 commit 219258c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/organize-problems.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: algorithmAutoSorter
on:
push:
branches: [ main ]

jobs:
uploadToNotion:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependency
run: pip install -r requirements.txt

- name: sort-and-upload-request
env:
REQUEST_URL: ${{ secrets.REQUEST_URL}}
COMMIT_MSG: ${{github.event.head_commit.message}}
PATTERN: ${{vars.COMMIT_PATTERN}}
run: python requestNotionUpload.py
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

config.ini
.venv
.env

# User-specific stuff
.idea
.idea/**/workspace.xml
Expand Down
70 changes: 70 additions & 0 deletions requestNotionUpload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import requests
import os
import configparser as parser
import re
import dotenv
import json


class Problem:
def __init__(self,title,id,lan,platform,level,memo=""):
self.title=title
self.id=id
self.lan=lan
self.platform=platform
self.level=level
self.memo=memo

def __str__(self):
return f"Title: {self.title}, ID: {self.id}, Language: {self.lan}, Platform: {self.platform}, Level: {self.level}, Memo: {self.memo}"

def request_notion_update(problem:Problem):

try:
print(f"\nRequest add new file to notion db : {problem.id} {problem.title}...")
response=requests.post(REQUEST_URL,problem.__dict__)
if response.status_code==200:
print("Successfully request\n")
else:
print(f"Request fail : {response.status_code} {response.text}\n")

except Exception as e:
print("An error occurred:", e)


if __name__=="__main__":

local_feed_url=""
local_request_url=""

if os.path.isfile('.env'):
print("load local .env")
dotenv.load_dotenv()
local_request_url=os.getenv('request_url')
local_commit_msg=os.getenv('commit_msg')
local_pattern=os.getenv('commit_pattern')


REQUEST_URL = os.environ['REQUEST_URL'] if os.environ.get('REQUEST_URL') != None else local_request_url
COMMIT_MSG = os.environ['COMMIT_MSG'] if os.environ.get('COMMIT_MSG') != None else local_commit_msg
PATTERN=os.environ['COMMIT_PATTERN'] if os.environ.get('COMMIT_PATTERN')!=None else local_pattern

print(PATTERN)
match=re.match(PATTERN,COMMIT_MSG)
print(match)

if match:
op, platform, level, id, title,lan = match.groups()
problem=Problem(
title=title,
id=id,
lan=lan,
platform=platform,
level=level
)

if op=="solve": request_notion_update(problem)

else:
print("not solve commit or parsing failed")

6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
certifi==2023.7.22
charset-normalizer==3.3.2
idna==3.4
python-dotenv==1.0.0
requests==2.31.0
urllib3==2.0.7

0 comments on commit 219258c

Please sign in to comment.