From 43943edd030af849ccdb3656f2c1351d7bfc23a5 Mon Sep 17 00:00:00 2001
From: Anmol Pratap Singh
Date: Wed, 22 Jul 2020 15:40:06 +0530
Subject: [PATCH 1/8] Update README.md
---
README.md | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/README.md b/README.md
index 66cde42..6ed15e5 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,12 @@
Let's check out in your profile readme!
+
+ Report Bug
+ Β·
+ Request Feature
+
+
## Prep Work
1. You need to update the markdown file(.md) with 2 comments. You can refer [here](#update-your-readme) for updating it.
From dc95f36f4e6ba284df45e7c2387a1b73491b48d3 Mon Sep 17 00:00:00 2001
From: Anmol Pratap Singh
Date: Wed, 22 Jul 2020 15:41:42 +0530
Subject: [PATCH 2/8] Update README.md
---
README.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 6ed15e5..7cab8a8 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,12 @@
# Dev Metrics in Readme with added feature flags π
-
+
- 
+ 
-
πβ¨Awesome Readme Stats
+ πβ¨Awesome Readme Stats
----
From 6304cddbb412534ac70c02bca1e00a51d13c4a6d Mon Sep 17 00:00:00 2001
From: Anmol Pratap Singh
Date: Wed, 22 Jul 2020 15:42:51 +0530
Subject: [PATCH 3/8] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 7cab8a8..b4c5099 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@

- πβ¨Awesome Readme Stats
+ πβ¨Awesome Readme Stats
----
From b5fdad5d6ca0970436139034c9eb41c51d7b4ae1 Mon Sep 17 00:00:00 2001
From: Anmol Pratap Singh
Date: Wed, 22 Jul 2020 15:49:27 +0530
Subject: [PATCH 4/8] Update LICENSE
---
LICENSE | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/LICENSE b/LICENSE
index 25a0263..2dc97fe 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2020 ATHUL CYRIAC AJAY
+Copyright (c) 2020 ANMOL PRATAP SINGH
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@@ -17,4 +17,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
From f3f3cef4f6a09c4615ed0f00ee6d3137d414101a Mon Sep 17 00:00:00 2001
From: Anmol Pratap Singh
Date: Wed, 22 Jul 2020 17:02:42 +0530
Subject: [PATCH 5/8] Update action.yml
---
action.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/action.yml b/action.yml
index 713ed84..4a2fba9 100644
--- a/action.yml
+++ b/action.yml
@@ -1,6 +1,6 @@
-name: 'Waka -- Readme Stats'
+name: 'Profile Readme Development Stats'
author: Anmol Pratap Singh
-description: 'Add a Wakatime Coding Activity graph in your Readme'
+description: 'Are you an early π€ or a night π¦? When are you most productive during the day? What languages you code in? And other stuff... Let's check out in your readme!'
inputs:
GH_TOKEN:
@@ -56,4 +56,4 @@ runs:
branding:
icon: 'activity'
- color: 'orange'
\ No newline at end of file
+ color: 'orange'
From b8dd657ff6be2d6a83360821be2c29eca7b8593a Mon Sep 17 00:00:00 2001
From: Anmol Pratap Singh
Date: Wed, 22 Jul 2020 17:37:40 +0530
Subject: [PATCH 6/8] Update action.yml
---
action.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/action.yml b/action.yml
index 4a2fba9..de45368 100644
--- a/action.yml
+++ b/action.yml
@@ -1,6 +1,6 @@
name: 'Profile Readme Development Stats'
author: Anmol Pratap Singh
-description: 'Are you an early π€ or a night π¦? When are you most productive during the day? What languages you code in? And other stuff... Let's check out in your readme!'
+description: 'Are you an early π€ or a night π¦? When are you most productive during the day? What languages you code in? And other stuff... Let''s check out in your readme!'
inputs:
GH_TOKEN:
From cd25d6f6a6d25ea192f2973d4b08d005928b1396 Mon Sep 17 00:00:00 2001
From: Anmol Pratap Singh
Date: Wed, 22 Jul 2020 17:39:50 +0530
Subject: [PATCH 7/8] Update action.yml
---
action.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/action.yml b/action.yml
index de45368..21f21fa 100644
--- a/action.yml
+++ b/action.yml
@@ -1,6 +1,6 @@
name: 'Profile Readme Development Stats'
author: Anmol Pratap Singh
-description: 'Are you an early π€ or a night π¦? When are you most productive during the day? What languages you code in? And other stuff... Let''s check out in your readme!'
+description: 'Are you an early π€ or a night π¦? When are you most productive during the day? Let''s check out in your readme!'
inputs:
GH_TOKEN:
From 85030a8a5bc66ca9ec3708c351843425c47c4755 Mon Sep 17 00:00:00 2001
From: Anmol
Date: Sun, 26 Jul 2020 17:17:04 +0530
Subject: [PATCH 8/8] FIX: COMMIT STATS BASED ON TIMEZONE OF THE USER
---
action.yml | 2 +-
main.py | 146 +++++++++++++++++++++++++++++++++++++----------------
2 files changed, 103 insertions(+), 45 deletions(-)
diff --git a/action.yml b/action.yml
index 21f21fa..b1e3815 100644
--- a/action.yml
+++ b/action.yml
@@ -56,4 +56,4 @@ runs:
branding:
icon: 'activity'
- color: 'orange'
+ color: 'orange'
\ No newline at end of file
diff --git a/main.py b/main.py
index 0203a68..bd2300f 100644
--- a/main.py
+++ b/main.py
@@ -5,8 +5,11 @@ Readme Development Metrics With waka time progress
import re
import os
import base64
+import sys
+from pytz import timezone
+import pytz
import requests
-from github import Github
+from github import Github, GithubException
import datetime
from string import Template
@@ -98,7 +101,7 @@ def make_list(data: list):
def make_commit_list(data: list):
'''Make List'''
data_list = []
- for l in data[:5]:
+ for l in data[:7]:
ln = len(l['name'])
ln_text = len(l['text'])
op = f"{l['name']}{' ' * (13 - ln)}{l['text']}{' ' * (15 - ln_text)}{make_graph(l['percent'])} {l['percent']}%"
@@ -106,11 +109,12 @@ def make_commit_list(data: list):
return ' \n'.join(data_list)
-def generate_commit_list():
+def generate_commit_list(tz):
+ string = ''
result = run_query(userInfoQuery) # Execute the query
username = result["data"]["viewer"]["login"]
id = result["data"]["viewer"]["id"]
- print("user {} id {}".format(username, id))
+ print("user {} id".format(username))
result = run_query(createContributedRepoQuery.substitute(username=username))
nodes = result["data"]["user"]["repositoriesContributedTo"]["nodes"]
@@ -121,14 +125,24 @@ def generate_commit_list():
evening = 0 # 18 - 24
night = 0 # 0 - 6
+ Monday = 0
+ Tuesday = 0
+ Wednesday = 0
+ Thursday = 0
+ Friday = 0
+ Saturday = 0
+ Sunday = 0
+
for repository in repos:
result = run_query(
createCommittedDateQuery.substitute(owner=repository["owner"]["login"], name=repository["name"], id=id))
try:
committed_dates = result["data"]["repository"]["ref"]["target"]["history"]["edges"]
for committedDate in committed_dates:
- date = datetime.datetime.strptime(committedDate["node"]["committedDate"], "%Y-%m-%dT%H:%M:%SZ")
+ date = datetime.datetime.strptime(committedDate["node"]["committedDate"],
+ "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=pytz.utc).astimezone(timezone(tz))
hour = date.hour
+ weekday = date.strftime('%A')
if 6 <= hour < 12:
morning += 1
if 12 <= hour < 18:
@@ -137,10 +151,26 @@ def generate_commit_list():
evening += 1
if 0 <= hour < 6:
night += 1
+
+ if weekday == "Monday":
+ Monday += 1
+ if weekday == "Tuesday":
+ Tuesday += 1
+ if weekday == "Wednesday":
+ Wednesday += 1
+ if weekday == "Thursday":
+ Thursday += 1
+ if weekday == "Friday":
+ Friday += 1
+ if weekday == "Saturday":
+ Saturday += 1
+ if weekday == "Sunday":
+ Sunday += 1
except Exception as ex:
- print("Exception occured" + str(ex));
+ print("Please Ignore this exception " + str(ex))
sumAll = morning + daytime + evening + night
+ sum_week = Sunday + Monday + Tuesday + Friday + Saturday + Wednesday + Thursday
if morning + daytime >= evening + night:
title = "I'm an early π€"
else:
@@ -151,50 +181,77 @@ def generate_commit_list():
{"name": "π Evening", "text": str(evening) + " commits", "percent": round((evening / sumAll) * 100, 2)},
{"name": "π Night", "text": str(night) + " commits", "percent": round((night / sumAll) * 100, 2)},
]
+ dayOfWeek = [
+ {"name": "Monday", "text": str(Monday) + " commits", "percent": round((Monday / sum_week) * 100, 2)},
+ {"name": "Tuesday", "text": str(Tuesday) + " commits", "percent": round((Tuesday / sum_week) * 100, 2)},
+ {"name": "Wednesday", "text": str(Wednesday) + " commits", "percent": round((Wednesday / sum_week) * 100, 2)},
+ {"name": "Thursday", "text": str(Thursday) + " commits", "percent": round((Thursday / sum_week) * 100, 2)},
+ {"name": "Friday", "text": str(Friday) + " commits", "percent": round((Friday / sum_week) * 100, 2)},
+ {"name": "Saturday", "text": str(Saturday) + " commits", "percent": round((Saturday / sum_week) * 100, 2)},
+ {"name": "Sunday", "text": str(Sunday) + " commits", "percent": round((Sunday / sum_week) * 100, 2)},
+ ]
- return '**' + title + '** \n\n' + '```text\n' + make_commit_list(one_day) + '\n\n```\n'
+ max_element = {
+ 'percent': 0
+ }
+
+ for day in dayOfWeek:
+ if day['percent'] > max_element['percent']:
+ max_element = day
+ days_title = 'I\'m Most Productive on ' + max_element['name'] + 's'
+ string = string + '**' + title + '** \n\n' + '```text\n' + make_commit_list(one_day) + '\n\n```\n'
+ string = string + 'π
**' + days_title + '** \n\n' + '```text\n' + make_commit_list(dayOfWeek) + '\n\n```\n'
+
+ return string
def get_stats():
'''Gets API data and returns markdown progress'''
stats = ''
- if showCommit.lower() in ['true', '1', 't', 'y', 'yes']:
- stats = stats + generate_commit_list() + '\n\n'
+ request = requests.get(f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}")
- try:
- request = requests.get(
- f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}")
+ if request.status_code == 200:
+ data = request.json()
+ if showCommit.lower() in ['true', '1', 't', 'y', 'yes']:
+ stats = stats + generate_commit_list(tz=data['data']['timezone']) + '\n\n'
+ stats = stats + 'π **This week I spent my time on** \n\n'
+ stats = stats + '```text\n'
+ if showTimeZone.lower() in ['true', '1', 't', 'y', 'yes']:
+ timezone = data['data']['timezone']
+ stats = stats + 'βοΈ Timezone: ' + timezone + '\n\n'
- if request.status_code == 200:
- data = request.json()
- stats = stats + 'π **This week I spent my time on** \n\n'
- stats = stats + '```text\n'
- if showTimeZone.lower() in ['true', '1', 't', 'y', 'yes']:
- timezone = data['data']['timezone']
- stats = stats + 'βοΈ Timezone: ' + timezone + '\n\n'
-
- if showLanguage.lower() in ['true', '1', 't', 'y', 'yes']:
+ if showLanguage.lower() in ['true', '1', 't', 'y', 'yes']:
+ if len(data['data']['languages']) != 0:
lang_list = make_list(data['data']['languages'])
- stats = stats + 'π¬ Languages: \n' + lang_list + '\n\n'
+ else:
+ lang_list = "No Activity tracked this Week"
+ stats = stats + 'π¬ Languages: \n' + lang_list + '\n\n'
- if showEditors.lower() in ['true', '1', 't', 'y', 'yes']:
+ if showEditors.lower() in ['true', '1', 't', 'y', 'yes']:
+ if len(data['data']['editors']) != 0:
edit_list = make_list(data['data']['editors'])
- stats = stats + 'π₯ Editors: \n' + edit_list + '\n\n'
+ else:
+ edit_list = "No Activity tracked this Week"
+ stats = stats + 'π₯ Editors: \n' + edit_list + '\n\n'
- if showProjects.lower() in ['true', '1', 't', 'y', 'yes']:
+ if showProjects.lower() in ['true', '1', 't', 'y', 'yes']:
+ if len(data['data']['projects']) != 0:
project_list = make_list(data['data']['projects'])
- stats = stats + 'π±βπ» Projects: \n' + project_list + '\n\n'
+ else:
+ project_list = "No Activity tracked this Week"
+ stats = stats + 'π±βπ» Projects: \n' + project_list + '\n\n'
- if showOs.lower() in ['true', '1', 't', 'y', 'yes']:
+ if showOs.lower() in ['true', '1', 't', 'y', 'yes']:
+ if len(data['data']['operating_systems']) != 0:
os_list = make_list(data['data']['operating_systems'])
- stats = stats + 'π» Operating Systems: \n' + os_list + '\n\n'
+ else:
+ os_list = "No Activity tracked this Week"
+ stats = stats + 'π» Operating Systems: \n' + os_list + '\n\n'
- stats = stats + '```\n\n'
- else:
- print("Waka Time Api Key Not Configured Properly")
- except Exception as e:
- print("Waka Time Api Key Not Configured" + str(e))
+ stats = stats + '```\n\n'
+ else:
+ print("Error With WAKA time API returned " + str(request.status_code) + " Response " + str(request.json()))
return stats
@@ -212,16 +269,17 @@ def generate_new_readme(stats: str, readme: str):
if __name__ == '__main__':
+ g = Github(ghtoken)
try:
- g = Github(ghtoken)
repo = g.get_repo(f"{user}/{user}")
- contents = repo.get_readme()
- headers = {"Authorization": "Bearer " + ghtoken}
- waka_stats = get_stats()
- rdmd = decode_readme(contents.content)
- new_readme = generate_new_readme(stats=waka_stats, readme=rdmd)
- if new_readme != rdmd:
- repo.update_file(path=contents.path, message='Updated with Dev Metrics',
- content=new_readme, sha=contents.sha, branch='master')
- except Exception as e:
- print("Exception Occurred" + str(e))
+ except GithubException:
+ print("Authentication Error. Try saving a GitHub Personal Access Token in your Repo Secrets")
+ sys.exit(1)
+ contents = repo.get_readme()
+ headers = {"Authorization": "Bearer " + ghtoken}
+ waka_stats = get_stats()
+ rdmd = decode_readme(contents.content)
+ new_readme = generate_new_readme(stats=waka_stats, readme=rdmd)
+ if new_readme != rdmd:
+ repo.update_file(path=contents.path, message='Updated with Dev Metrics',
+ content=new_readme, sha=contents.sha, branch='master')
\ No newline at end of file