From 4641b4462c8a9d96202bb5d334b705e321d28e8c Mon Sep 17 00:00:00 2001 From: Geoff Riley Date: Tue, 12 Oct 2021 15:11:10 +0100 Subject: [PATCH 1/2] PCC38 GeoffRiley: Aborted attempt Kept exceeding API limits at GitHub. Need a better understanding of the API before trying again. --- 38/GeoffRiley/git_check.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 38/GeoffRiley/git_check.py diff --git a/38/GeoffRiley/git_check.py b/38/GeoffRiley/git_check.py new file mode 100644 index 000000000..fb4fb9863 --- /dev/null +++ b/38/GeoffRiley/git_check.py @@ -0,0 +1,14 @@ +import argparse + +from github import Github + +parse = argparse.ArgumentParser() +parse.add_argument('user', help="GitHub username") +parse.add_argument('password', help="GiHub password") +args = parse.parse_args() + +gh = Github(login_or_token=args.user, password=args.password) +user = gh.get_user() +repos = user.get_repos() +for repo in repos: + print(f'{repo.name}') From 9ccef509e8a19d555346649e8ca153a8e342ecfc Mon Sep 17 00:00:00 2001 From: Geoff Riley Date: Sat, 29 Oct 2022 23:29:11 +0100 Subject: [PATCH 2/2] =?UTF-8?q?PCC38=20GeoffRiley=20=E2=80=94=20HacktoberF?= =?UTF-8?q?est=20Checker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All sorted now, bottle app working nicely. --- 38/GeoffRiley/git_check.py | 88 ++++++++++++++++++++++++++++----- 38/GeoffRiley/views/pr_list.tpl | 11 +++++ 38/GeoffRiley/views/unknown.tpl | 2 + 3 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 38/GeoffRiley/views/pr_list.tpl create mode 100644 38/GeoffRiley/views/unknown.tpl diff --git a/38/GeoffRiley/git_check.py b/38/GeoffRiley/git_check.py index fb4fb9863..81f62d089 100644 --- a/38/GeoffRiley/git_check.py +++ b/38/GeoffRiley/git_check.py @@ -1,14 +1,80 @@ -import argparse +from datetime import date -from github import Github +from bottle import run, template, request, post, get +from github import Github, GithubException -parse = argparse.ArgumentParser() -parse.add_argument('user', help="GitHub username") -parse.add_argument('password', help="GiHub password") -args = parse.parse_args() -gh = Github(login_or_token=args.user, password=args.password) -user = gh.get_user() -repos = user.get_repos() -for repo in repos: - print(f'{repo.name}') +@get('/') +def login(): + return ''' +

HacktoberFest Checker

+

Login

+

Please enter your Github username

+
+ Github username: +
+ ''' + + +@post('/') +def search_prs(): + # Statements taken from https://github.com/pybites/hacktoberfest-checker/blob/master/controllers/index.js + statements = [ + "It's not too late to start!", + "Off to a great start, keep going!", + "Half way there, keep it up!", + "So close!", + "Way to go!", + "Now you're just showing off!" + ] + # Extract the username entered in the web form + username = request.forms.get('username') + + # check with GitHub that the entered username actually exists… if not show the unknown template + gh = Github() + try: + user = gh.get_user(username).name + except GithubException: + return template('unknown') + + # Now we're going to grab a list of all the PRs put through by the user… there should be more checking though, ie: + # for invalid and spam labels at the very least. + try: + # Query based upon: + # const options = { + # q: `-label:invalid + # +created:2017-09-30T00:00:00-12:00..2017-10-31T23:59:59-12:00 + # +type:pr + # +is:public + # +author:${username}` + # }; + # from https://github.com/pybites/hacktoberfest-checker/blob/master/controllers/index.js + # The was written for 2017, so it needs to be updated for *this* year, + # we can automagically pick the current year: + year = str(date.today().year) + # Request a list of PRs within the specific date range… + query = f'{year}-09-30T00:00:00-12:00..{year}-10-31T23:59:59-12:00' + pr_list = gh.search_issues('', author=username, type='pr', created=query) + except GithubException: + # any errors from GitHub at this stage we just assumes means no PRs found + pr_list = [] + pr_list.totalCount = 0 + + # We're going to pick out the details for each PR that we want to display to the user + pr_detail = {"url": [], "title": [], "date": []} + # Provided there are PRs, loop through them extracting the url, title and date into the pr_detail arrays + if pr_list.totalCount > 0: + for pr in pr_list: + pr_detail["url"].append(pr.pull_request.html_url) + pr_detail["title"].append(pr.title) + pr_detail["date"].append(pr.created_at) + + pr_count = len(pr_detail["title"]) + return template('pr_list', pr_data=pr_detail, name=pr_list[0].user.name, + prs=pr_detail["title"], dates=pr_detail["date"], urls=pr_detail["url"], + pr_count=pr_count, statement=statements[pr_count]) + + return template('pr_list', pr_count=0, name=user, statement=statements[0]) + + +run(host='localhost', port=8080) diff --git a/38/GeoffRiley/views/pr_list.tpl b/38/GeoffRiley/views/pr_list.tpl new file mode 100644 index 000000000..56d039acf --- /dev/null +++ b/38/GeoffRiley/views/pr_list.tpl @@ -0,0 +1,11 @@ +

HacktoberFest Checker

+

{{name}}

+

You have {{pr_count}} out of 4 PRs completed this October.

+

{{statement}}

+%if 'prs' in locals(): + +%end \ No newline at end of file diff --git a/38/GeoffRiley/views/unknown.tpl b/38/GeoffRiley/views/unknown.tpl new file mode 100644 index 000000000..4e19653e3 --- /dev/null +++ b/38/GeoffRiley/views/unknown.tpl @@ -0,0 +1,2 @@ +

HacktoberFest Checker

+

Sorry, could not find a user on Github with that name, please check and try again.

\ No newline at end of file