Skip to content

Commit

Permalink
Merge branch 'Alpha' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
anmol098 committed Jul 28, 2020
2 parents 7320e98 + 09764da commit 2aa951e
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 157 deletions.
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,27 @@ jobs:
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
USERNAME: <username> # optional, it will automatically use the username of the owner of the repository who's executing the workflow.
```
## Extras
1. If you want to add the other info to your stats, you can add multiple `FLAGS` in your workflow file by default all flags are enabled
1. If you want to add the other info to your stats, you can add multiple `FLAGS` in your workflow file by default all flags are enabled
>except the lines of code flag due to heavy operation performed

```yml
- uses: anmol098/waka-readme-stats@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
USERNAME: <username>
SHOW_OS: "False"
SHOW_PROJECTS: "False"
```

#### Flags Available
`SHOW_LINES_OF_CODE` flag can be set to `True` to show the Lines of code writen till date

![Lines of code](https://img.shields.io/badge/From%20Hello%20World%20I've%20written-12,66,814%20Lines%20of%20code-blue)


`SHOW_COMMIT` flag can be set to `False` to hide the commit stats

**I'm an early 🐤**
Expand All @@ -120,6 +124,18 @@ jobs:
🌃 Evening 112 commits █████████░░░░░░░░░░░░░░░░ 36.01%
🌙 Night 26 commits ██░░░░░░░░░░░░░░░░░░░░░░░ 8.36%
```
📅 **I'm Most Productive on Sundays**

```text
Monday 50 commits ███░░░░░░░░░░░░░░░░░░░░░░ 13.19%
Tuesday 85 commits █████░░░░░░░░░░░░░░░░░░░░ 22.43%
Wednesday 56 commits ███░░░░░░░░░░░░░░░░░░░░░░ 14.78%
Thursday 44 commits ███░░░░░░░░░░░░░░░░░░░░░░ 11.61%
Friday 28 commits █░░░░░░░░░░░░░░░░░░░░░░░░ 7.39%
Saturday 30 commits ██░░░░░░░░░░░░░░░░░░░░░░░ 7.92%
Sunday 86 commits █████░░░░░░░░░░░░░░░░░░░░ 22.69%
```

`SHOW_LANGUAGE` flag can be set to `False` to hide the Coding Language You use
Expand Down Expand Up @@ -167,6 +183,27 @@ PhpStorm 1 hr 35 mins ████░░░░░░░
PyCharm 23 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 4.49%
```

## :sparkling_heart: Support the project

I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
this takes time. You can use this service for free.

However, if you are using this project and happy with it or just want to encourage me to continue creating stuff, there are few ways you can do it :-

- Giving proper credit when you use this action on your readme, linking back to it :D
- Starring and sharing the project :rocket:
- [![paypal.me/aapreneur](https://ionicabizau.github.io/badges/paypal.svg)](https://www.paypal.me/aapreneur) - You can make one-time donations via PayPal. I'll probably buy a ~~beer~~ wine 🍷

Thanks! :heart:

---

Contributions are welcomed! ♥

Made with :heart: and Python 🐍.



> This project is inspired by an awesome pinned-gist project [Awesome Pinned Gists](https://github.com/matchai/awesome-pinned-gists) <br/>
>This project is inspired from [athul/waka-readme](https://github.com/athul/waka-readme)

Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ inputs:
description: "Show the Coding language used in dev metrics"
default: "True"

SHOW_LINES_OF_CODE:
required: false
description: "Show the Total Lines of code written Badge till date"
default: "False"

SHOW_LANGUAGE_PER_REPO:
required: false
description: ""
default: "True"

SHOW_LOC_CHART:
required: false
description: ""
default: "True"



Expand Down
108 changes: 52 additions & 56 deletions loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import datetime
from string import Template
import matplotlib.pyplot as plt
from io import StringIO,BytesIO
from io import StringIO, BytesIO
from dotenv import load_dotenv
import time

Expand All @@ -15,70 +15,70 @@

class LinesOfCode:

def __init__(self,id,username,ghtoken, repositoryData):
self.id=id
self.username=username
def __init__(self, id, username, ghtoken, repositoryData):
self.id = id
self.username = username

self.g = Github(ghtoken)
self.headers = {"Authorization": "Bearer " + ghtoken}
self.repositoryData=repositoryData
self.g = Github(ghtoken)
self.headers = {"Authorization": "Bearer " + ghtoken}
self.repositoryData = repositoryData

def calculateLoc(self):
result=self.repositoryData
yearly_data={}
result = self.repositoryData
yearly_data = {}
for repo in result['data']['user']['repositories']['edges']:
print(repo)
self.getCommitStat(repo['node'],yearly_data)
time.sleep(0.7)
print(repo)
self.getCommitStat(repo['node'], yearly_data)
time.sleep(0.7)
print("\n\n")
print(yearly_data)
graph=BarGraph(yearly_data)
graph_file=graph.build_graph()
print("here")
graph = BarGraph(yearly_data)
graph_file = graph.build_graph()
self.pushChart()

def run_query_v3(self,nameWithOwner):
endPoint='https://api.github.com/repos/'+nameWithOwner+'/stats/code_frequency'
def run_query_v3(self, nameWithOwner):
endPoint = 'https://api.github.com/repos/' + nameWithOwner + '/stats/code_frequency'
# print(endPoint)
request = requests.get(endPoint, headers=self.headers)
if request.status_code == 401:
raise Exception("Invalid token {}. {}".format(request.status_code, nameWithOwner))
raise Exception("Invalid token {}. {}".format(request.status_code, nameWithOwner))
return request.json()

def getQuarter(self,timeStamp):
month=datetime.datetime.fromtimestamp(timeStamp).month
if month>=1 and month<=4:
return 1
elif month>=5 and month<=8:
return 2
elif month>=9 and month<=12:
return 3

def getQuarter(self, timeStamp):
month = datetime.datetime.fromtimestamp(timeStamp).month
if month >= 1 and month <= 4:
return 1
elif month >= 5 and month <= 8:
return 2
elif month >= 9 and month <= 12:
return 3

def getCommitStat(self,repoDetails,yearly_data):
result= self.run_query_v3(repoDetails['nameWithOwner'])
this_year=datetime.datetime.utcnow().year
def getCommitStat(self, repoDetails, yearly_data):
result = self.run_query_v3(repoDetails['nameWithOwner'])
this_year = datetime.datetime.utcnow().year

for i in range(len(result)):
curr_year=datetime.datetime.fromtimestamp(result[i][0]).year
# if curr_year != this_year:
quarter=self.getQuarter(result[i][0])
if repoDetails['primaryLanguage'] is not None:

if curr_year not in yearly_data:
yearly_data[curr_year]={}
if quarter not in yearly_data[curr_year]:
yearly_data[curr_year][quarter]={}
if repoDetails['primaryLanguage']['name'] not in yearly_data[curr_year][quarter]:
yearly_data[curr_year][quarter][repoDetails['primaryLanguage']['name']]=0
yearly_data[curr_year][quarter][repoDetails['primaryLanguage']['name']]+=(result[i][1]+result[i][2])

#to find total

# if 'total' not in yearly_data[curr_year]:
# yearly_data[curr_year]['total']={}
# if repoDetails['primaryLanguage']['name'] not in yearly_data[curr_year]['total']:
# yearly_data[curr_year]['total'][repoDetails['primaryLanguage']['name']]=0
# yearly_data[curr_year]['total'][repoDetails['primaryLanguage']['name']]+=(result[i][1]+result[i][2])
curr_year = datetime.datetime.fromtimestamp(result[i][0]).year
# if curr_year != this_year:
quarter = self.getQuarter(result[i][0])
if repoDetails['primaryLanguage'] is not None:

if curr_year not in yearly_data:
yearly_data[curr_year] = {}
if quarter not in yearly_data[curr_year]:
yearly_data[curr_year][quarter] = {}
if repoDetails['primaryLanguage']['name'] not in yearly_data[curr_year][quarter]:
yearly_data[curr_year][quarter][repoDetails['primaryLanguage']['name']] = 0
yearly_data[curr_year][quarter][repoDetails['primaryLanguage']['name']] += (result[i][1] + result[i][2])

# to find total

# if 'total' not in yearly_data[curr_year]:
# yearly_data[curr_year]['total']={}
# if repoDetails['primaryLanguage']['name'] not in yearly_data[curr_year]['total']:
# yearly_data[curr_year]['total'][repoDetails['primaryLanguage']['name']]=0
# yearly_data[curr_year]['total'][repoDetails['primaryLanguage']['name']]+=(result[i][1]+result[i][2])

def pushChart(self):
repo = self.g.get_repo(f"{self.username}/{self.username}")
Expand All @@ -88,13 +88,9 @@ def pushChart(self):
contents = repo.get_contents("charts/bar_graph.png")
repo.update_file(contents.path, "Charts Added", data, contents.sha)
except Exception as e:
repo.create_file("charts/bar_graph.png", "Initial Commit",data)
repo.create_file("charts/bar_graph.png", "Initial Commit", data)
print("pushed")





# if __name__ == '__main__':
# try:
# g = Github(ghtoken)
Expand All @@ -103,7 +99,7 @@ def pushChart(self):
# username = user_data["data"]["viewer"]["login"]
# id = user_data["data"]["viewer"]["id"]
# print("user {} id {}".format(username, id))

# getLoc()

# # repo = g.get_repo(f"{username}/{username}")
Expand All @@ -117,4 +113,4 @@ def pushChart(self):
# # content=new_readme, sha=contents.sha, branch='master')
# # print("Readme updated")
# except Exception as e:
# print("Exception Occurred" + str(e))
# print("Exception Occurred" + str(e))
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def run_v3_api(query):
repositoryListQuery = Template("""
{
user(login: "$username") {
repositories(orderBy: {field: CREATED_AT, direction: ASC}, last: 100, affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER], isFork: false) {
repositories(orderBy: {field: CREATED_AT, direction: ASC}, last: 5, affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER], isFork: false) {
totalCount
edges {
node {
Expand Down Expand Up @@ -280,6 +280,8 @@ def generate_commit_list(tz):
string = string + '📅 **' + days_title + '** \n\n' + '```text\n' + make_commit_list(dayOfWeek) + '\n\n```\n'
return string



def get_waka_time_stats():
stats = ''
request = requests.get(
Expand Down
Loading

0 comments on commit 2aa951e

Please sign in to comment.