github-streak 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ghstreak/__init__.py ADDED
File without changes
ghstreak/streak.py ADDED
@@ -0,0 +1,111 @@
1
+ from datetime import date, timedelta
2
+ import os
3
+ import requests
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ def get_contributions(username, days=365):
10
+ # GitHub GraphQL API to get contribution calendar
11
+ token = os.getenv('GITHUB_TOKEN')
12
+
13
+ if not token:
14
+ print("Warning: No GITHUB_TOKEN found. API rate limits will be very restrictive.")
15
+ print("To fix this, set your token: export GITHUB_TOKEN=your_token_here")
16
+ print("You can create a token at: https://github.com/settings/tokens")
17
+ print()
18
+
19
+ from_date = (date.today() - timedelta(days=days)).isoformat() + "T00:00:00Z"
20
+ to_date = date.today().isoformat() + "T23:59:59Z"
21
+
22
+ query = f"""
23
+ query {{
24
+ user(login: "{username}") {{
25
+ contributionsCollection(from: "{from_date}", to: "{to_date}") {{
26
+ contributionCalendar {{
27
+ weeks {{
28
+ contributionDays {{
29
+ date
30
+ contributionCount
31
+ }}
32
+ }}
33
+ }}
34
+ }}
35
+ }}
36
+ }}
37
+ """
38
+
39
+ headers = {
40
+ "Authorization": f"Bearer {token}",
41
+ "Content-Type": "application/json"
42
+ } if token else {"Content-Type": "application/json"}
43
+
44
+ try:
45
+ response = requests.post(
46
+ "https://api.github.com/graphql",
47
+ json={"query": query},
48
+ headers=headers
49
+ )
50
+ response.raise_for_status()
51
+ result = response.json()
52
+
53
+ if 'errors' in result:
54
+ raise Exception(f"GraphQL Error: {result['errors']}")
55
+
56
+ days_data = []
57
+ for week in result['data']['user']['contributionsCollection']['contributionCalendar']['weeks']:
58
+ for day in week['contributionDays']:
59
+ days_data.append({
60
+ "date": day["date"],
61
+ "count": day["contributionCount"]
62
+ })
63
+ return sorted(days_data, key=lambda x: x["date"], reverse=True)
64
+
65
+ except requests.exceptions.HTTPError as e:
66
+ if e.response.status_code == 403:
67
+ raise Exception("GitHub API rate limit exceeded. Please set GITHUB_TOKEN environment variable.")
68
+ raise
69
+
70
+ def analyze_streaks(days_data):
71
+ current_streak = 0
72
+ previous_streak = 0
73
+ gap_found = False
74
+ last_active_day = None
75
+
76
+ for i, day in enumerate(days_data):
77
+ if day['count'] > 0:
78
+ if not gap_found:
79
+ current_streak += 1
80
+ else:
81
+ previous_streak += 1
82
+ else:
83
+ if not gap_found:
84
+ gap_found = True
85
+ last_active_day = days_data[i-1]["date"] if i > 0 else None
86
+ elif previous_streak > 0:
87
+ break
88
+
89
+ return {
90
+ "current_streak": current_streak,
91
+ "previous_streak": previous_streak,
92
+ "last_active_day": last_active_day
93
+ }
94
+
95
+ def main():
96
+ import sys
97
+ if len(sys.argv) != 2:
98
+ print("Usage: ghstreak <github_username>")
99
+ sys.exit(1)
100
+
101
+ username = sys.argv[1]
102
+ data = get_contributions(username)
103
+ result = analyze_streaks(data)
104
+ print(f"Current streak: {result['current_streak']} days")
105
+ if result['previous_streak'] > 0:
106
+ print(f"Previous streak: {result['previous_streak']} days, ended on {result['last_active_day']}")
107
+ else:
108
+ print("No previous streak found")
109
+
110
+ if __name__ == "__main__":
111
+ main()
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: github-streak
3
+ Version: 0.1.0
4
+ Summary: CLI tool to track your GitHub contribution streaks
5
+ Author: Deven Mistry
6
+ Project-URL: Homepage, https://github.com/deven367/github-streak
7
+ Project-URL: Repository, https://github.com/deven367/github-streak
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.7
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Requires-Python: >=3.7
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: requests>=2.25.0
19
+ Requires-Dist: python-dotenv>=0.19.0
20
+
21
+ # ghstreak
22
+
23
+ A simple CLI tool to track your GitHub contribution streaks.
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install ghstreak
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```bash
34
+ ghstreak <github_username>
35
+ ```
36
+
37
+ Example:
38
+
39
+ ```bash
40
+ ghstreak deven367
41
+ ```
42
+
43
+ ## Authentication
44
+
45
+ For higher API rate limits, set your GitHub token as an environment variable:
46
+
47
+ ```bash
48
+ export GITHUB_TOKEN=your_token_here
49
+ ```
50
+
51
+ You can create a personal access token at: <https://github.com/settings/tokens>
52
+
53
+ ## Output
54
+
55
+ The tool displays:
56
+
57
+ - Your current contribution streak (consecutive days with contributions)
58
+ - Your previous streak (if applicable) and when it ended
59
+
60
+ ## Requirements
61
+
62
+ - Python >= 3.7
63
+ - requests >= 2.25.0
64
+ - python-dotenv >= 0.19.0
@@ -0,0 +1,7 @@
1
+ ghstreak/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ghstreak/streak.py,sha256=gEDgyxN4qJQVjlW42-NJezwhCnGEnW1_Kds75QrurQM,3384
3
+ github_streak-0.1.0.dist-info/METADATA,sha256=-d-G9LB9S2DcROEq8y-9luAAl_8uFj1kBguIuEel_VY,1487
4
+ github_streak-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
+ github_streak-0.1.0.dist-info/entry_points.txt,sha256=prQ9oElrS68913jpoKqz1OAj0tlIkYvFWQIcOWomjh0,50
6
+ github_streak-0.1.0.dist-info/top_level.txt,sha256=cpbUjQE2f5SeZpD6kgfQC7Z0GMxubFNDjeUIMLTbClY,9
7
+ github_streak-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ghstreak = ghstreak.streak:main
@@ -0,0 +1 @@
1
+ ghstreak