Created
October 7, 2021 07:17
-
-
Save imkaka/3804be4eebb4bfc53a471b77141858ee to your computer and use it in GitHub Desktop.
Know If you have completed the Hacktoberfest Challenge!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import sys | |
from urllib import request | |
from datetime import datetime | |
from dateutil.tz import tzutc | |
from dateutil.parser import parse | |
# Change year here for each year. | |
start_time = datetime(2021, 10, 1, 0, 0, tzinfo=tzutc()) | |
def check_done(username): | |
"""Checks if user has made pull quota""" | |
count = 0 | |
resp = request.urlopen(f"https://api.github.com/users/{username}/events") | |
for event in json.loads(resp.read()): | |
if event['type'] == "PullRequestEvent" and event['payload']['action'] == "opened": | |
time = parse(event['created_at']) | |
if time >= start_time: | |
count += 1 | |
return f"Yes: {username} is done with {count} pull requests" if count >= 4 else f"No: {username} needs {4 - count} more pull requests" | |
if __name__ == "__main__": | |
if len(sys.argv) == 2: | |
print(check_done(sys.argv[1])) | |
else: | |
print("Usage: hacto.py <github username>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment