-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create github action workflow and script
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |