122 lines
2.6 KiB
Python
122 lines
2.6 KiB
Python
"""
|
|
Leetcode status visualizer!
|
|
Contains status bar and skills box
|
|
|
|
status bar like this:
|
|
|
|
```txt
|
|
Total solved: xxx
|
|
|
|
Easy: xxx/xxx Beats xx%
|
|
XXXX..........
|
|
|
|
Medium: xxx/xxx Beats xx%
|
|
XXXX..........
|
|
|
|
Hard: xxx/xxx Beats xx%
|
|
XXXX..........
|
|
```
|
|
|
|
skills box like this:
|
|
|
|
```txt
|
|
Top Leetcode Skills
|
|
|
|
1. Divide and Conquer (1) XXXXX..... Advanced
|
|
2. Trie (1) XXXXX..... Advanced
|
|
3. Hash Table (1) XXXXX..... Intermediate
|
|
4. Math (3) XXXXX..... Intermediate
|
|
5. Recursion (1) XX........ Intermediate
|
|
```
|
|
"""
|
|
|
|
# standard
|
|
import sys
|
|
import os
|
|
from dataclasses import dataclass
|
|
import base64
|
|
|
|
# external
|
|
|
|
import gitea
|
|
import requests
|
|
|
|
############## data ##################
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class LeetcodeInput:
|
|
"""Leetcode Input Env Varidables."""
|
|
|
|
# constants
|
|
prefix_length: int = 16
|
|
graph_length: int = 25
|
|
|
|
# mapped env var
|
|
# # required
|
|
gitea_token: str = os.getenv("GITHUB_TOKEN")
|
|
gitea_url: str = os.getenv("GITHUB_SERVER_URL")
|
|
leetcode_username: str = os.getenv("USERNAME")
|
|
gitea_username: str = os.getenv("GITHUB_REPOSITORY").split("/")[0]
|
|
gitea_repo: str = os.getenv("GITHUB_REPOSITORY").split("/")[1]
|
|
gitea_branch: str = os.getenv("GITHUB_REF_NAME")
|
|
|
|
# # depends
|
|
commit_message: str = os.getenv("INPUT_COMMIT_MESSAGE", "Update leetcode status")
|
|
|
|
def validate_input(self) -> bool:
|
|
"""Validate Input Env Var"""
|
|
if not self.gitea_token or not self.gitea_url or not self.leetcode_username:
|
|
return False
|
|
return True
|
|
|
|
|
|
############# logic ###################
|
|
|
|
|
|
def make_title() -> str:
|
|
"""Count total solved number"""
|
|
pass
|
|
|
|
|
|
def make_graph() -> str:
|
|
"""Make graph from the API's data"""
|
|
pass
|
|
|
|
|
|
def fetch_data() -> str:
|
|
"""Fetch data from leetcode api"""
|
|
pass
|
|
|
|
|
|
def update_readme(new_content):
|
|
"""Update and push"""
|
|
b64_new_content = base64.b64encode(bytes(new_content, encoding="utf-8"))
|
|
repo_content = git
|
|
pass
|
|
|
|
|
|
def genesis() -> None:
|
|
"""Run Program"""
|
|
gitea_connection = gitea.Gitea(lc_i.gitea_url, lc_i.gitea_token)
|
|
|
|
gitea_repo = gitea.Repository.request(
|
|
gitea_connection, lc_i.gitea_username, lc_i.gitea_repo
|
|
)
|
|
|
|
readme_raw_data = fetch_raw_readme()
|
|
readme_contents = str(base64.b64decode(readme_raw_data), encoding="utf-8")
|
|
if not (new_content := churn(readme_contents)):
|
|
return
|
|
|
|
|
|
if __name__ == "__main__":
|
|
lc_i = LeetcodeInput()
|
|
if not lc_i.validate_input():
|
|
print("Input error")
|
|
sys.exit(1)
|
|
|
|
genesis()
|
|
|
|
print("\nThanks for using Leetcode readme")
|