Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get all contributes since registration #20

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions graphql_query.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
"""Query for github graphql api"""
from os import getenv
from os import getenv, linesep
from datetime import datetime

QUERY = f"""
{{
user(login: "{getenv("INPUT_GITHUB_USERNAME")}") {{
contributionsCollection {{
# get the current year
current_year = datetime.now().year
contribution_list = []

# in a later version we can replace the 2015 date with user input
while current_year >= 2015:

temp_query = f"""
{"_" + str(current_year)}: contributionsCollection(from: "{str(current_year)}-01-01T00:00:00") {{
contributionCalendar {{
totalContributions
}}
}}
"""

contribution_list.append(temp_query)
current_year -= 1

QUERY = f"""
{{
user(login: "{getenv("INPUT_GITHUB_USERNAME")}") {{
{linesep.join(contribution_list)}
followers {{
totalCount
}}
Expand Down
17 changes: 15 additions & 2 deletions readme_level.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module that contains all the logic about the levelsystem."""
from os import getenv
from datetime import datetime
from logging import exception, info
from requests import post
from graphql_query import QUERY
Expand Down Expand Up @@ -34,8 +35,20 @@ def fetch_user_data(self) -> dict[str, int] | None:

response_data = response.json()

user_data = (response_data["data"]["user"]
["contributionsCollection"]["contributionCalendar"])
current_year = datetime.now().year
total_contribution = []

while current_year >= 2015:
contribution_count = (response_data["data"]["user"]
["_" + str(current_year)]["contributionCalendar"]["totalContributions"])

total_contribution.append(contribution_count)
current_year -= 1


user_data = {}

user_data["totalContributions"] = sum(total_contribution)

user_data["totalFollowers"] = (response_data["data"]["user"]
["followers"]["totalCount"])
Expand Down
Loading