diff --git a/README.md b/README.md index c3b8b22..b9773b1 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,28 @@ [Wakatime](https://wakatime.com) Weekly Metrics on your Profile Readme +## Update your Readme + +Add a comment to your README like the follows + +```md + + +``` + +The lines will be our entrypoints for our metrics. + ## How to get it -**You Need to Have [waka-box](https://github.com/matchai/waka-box) in your Repo** -> *This maybe temporary and will be updated soon as I'll update this to an Action* - Clone the Repo - Install the dependencies `pip install -r requirements.txt` -- Get a GitHub Access Token with a `repo` scope +- Get a GitHub Access Token with a `repo` scope. +- Get your Wakatime API Key. - Load env vars like ```text GH_TOKEN = - GIST_ID = + WAKATIME_API_KEY = USERNAME = ``` diff --git a/main.py b/main.py index 45a30ce..def8cc4 100644 --- a/main.py +++ b/main.py @@ -9,28 +9,49 @@ END_COMMENT = '' listReg = f'{START_COMMENT}[\\s\\S]+{END_COMMENT}' user = os.getenv("USERNAME") -gistid = os.getenv("GIST_ID") +waka_key = os.getenv("WAKATIME_API_KEY") ghtoken = os.getenv("GH_TOKEN") + +def makeGraph(percent: float): + done_block = "█" + empty_block = "░" + pc_rnd = round(percent) + return (f'{done_block*int(pc_rnd/4)}{empty_block*int( 25-int(pc_rnd/4))}') + + def getStats(): - data = requests.get(f"https://gist.githubusercontent.com/{user}/{gistid}/raw/").text + data = requests.get( + f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}").json() + lang_data = data['data']['languages'] + data_list = [] + for l in lang_data[:5]: + ln = len(l['name']) + ln_text = len(l['text']) + op = f"{l['name']}{' '*(12-ln)}{l['text']}{' '*(20-ln_text)}{makeGraph(l['percent'])} {l['percent']}" + data_list.append(op) + data = " \n".join(data_list) return ("```text\n"+data+"\n```") - -def decodeReadme(data:str): + + +def decodeReadme(data: str): decodedBytes = base64.b64decode(data) decodedStr = str(decodedBytes, "utf-8") return decodedStr -def generatenewReadme(stats:str,readme:str): + +def generatenewReadme(stats: str, readme: str): statsinReadme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}" - newReadme = re.sub(listReg,statsinReadme,readme) + newReadme = re.sub(listReg, statsinReadme, readme) return newReadme + if __name__ == '__main__': g = Github(ghtoken) repo = g.get_repo(f"{user}/{user}") contents = repo.get_readme() stats = getStats() rdmd = decodeReadme(contents.content) - newreadme = generatenewReadme(stats=stats,readme=rdmd) - repo.update_file(path=contents.path,message="Updated with Dev Metrics",content=newreadme,sha=contents.sha,branch="master") \ No newline at end of file + newreadme = generatenewReadme(stats=stats, readme=rdmd) + repo.update_file(path=contents.path, message="Updated with Dev Metrics", + content=newreadme, sha=contents.sha, branch="master")