diff --git a/.github/workflows/organize-problems.yml b/.github/workflows/organize-problems.yml new file mode 100644 index 0000000..f3cb95e --- /dev/null +++ b/.github/workflows/organize-problems.yml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4379d76..346adf7 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/requestNotionUpload.py b/requestNotionUpload.py new file mode 100644 index 0000000..cd79a00 --- /dev/null +++ b/requestNotionUpload.py @@ -0,0 +1,71 @@ +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) + + problem={} + 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") + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6b99d4b --- /dev/null +++ b/requirements.txt @@ -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