From 7ef9596d2db6ed1461ce11776ddcc67c253e22cc Mon Sep 17 00:00:00 2001 From: Greg Sutcliffe Date: Thu, 26 May 2016 14:03:26 +0100 Subject: [PATCH] Fixes #1 - add --rate-limit command Adds a --rate-limit switch which simply queries the remaining API requests for the specified login/token and displays it along with the time of the next reset --- bin/pullpo | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/pullpo b/bin/pullpo index 62d4b53..41fe429 100755 --- a/bin/pullpo +++ b/bin/pullpo @@ -21,6 +21,8 @@ # Santiago DueƱas # +import datetime + from argparse import ArgumentParser from pullpo.backends import BackendError @@ -52,6 +54,16 @@ def main(): backend = GitHubBackend(args.gh_user, args.gh_password, args.gh_token, session, enterprise_url=args.gh_url) + if args.rate_limit: + print('Remaining rate limit requests: ' + str(backend.gh.rate_limit()['rate']['remaining'])) + print('Rate limit requests reset at: ' + str(datetime.datetime.fromtimestamp(backend.gh.rate_limit()['rate']['reset']))) + sys.exit(0) + + + if args.rate_limit: + print('Remaining rate limit requests: ' + str(backend.gh.rate_limit()['rate']['remaining'])) + print('Rate limit requests reset at: ' + str(datetime.datetime.fromtimestamp(backend.gh.rate_limit()['rate']['reset']+3600))) + sys.exit(0) for repo in backend.fetch(args.owner, args.repository, since, newest): store(db, session, repo) @@ -109,6 +121,10 @@ def parse_args(): action='store_true', help='Retrieve newest issues first', default=False) + group.add_argument('--rate-limit', dest='rate_limit', + action='store_true', + help='Display rate limit info for the GitHub login', + default=False) # Positional arguments parser.add_argument('owner', help='Owner of the repository on GitHub')