From d5f97abe8db56663aac88fc19cc3e1985e81d5f5 Mon Sep 17 00:00:00 2001 From: Andrew Grant Date: Sun, 3 May 2020 23:02:00 -0400 Subject: [PATCH] Authentiate via 'credentials' to extend API request limit from 60x -> 5000x --- .gitignore | 3 ++- OpenBench/utils.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 771f15d..27f78f3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ Client/* !Client/OpenBench.py !Client/Client.py !Client/cleanup.sh -OpenBench/migrations/* \ No newline at end of file +OpenBench/migrations/* +credentials \ No newline at end of file diff --git a/OpenBench/utils.py b/OpenBench/utils.py index d5f5ce5..e78f7e3 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -18,7 +18,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -import math, re, requests, random, datetime +import math, re, requests, random, datetime, os import OpenBench.models, OpenBench.stats @@ -135,7 +135,14 @@ def getBranch(request, errors, name): target = pathjoin(target, url, branch).rstrip('/') try: - data = requests.get(target).json() + + if os.path.exists('credentials'): + with open('credentials') as fin: + user, token = fin.readlines()[0].rstrip().split() + auth = requests.auth.HTTPBasicAuth(user, token) + else: auth = None + + data = requests.get(target, auth=auth).json() data = data if bysha else data['commit'] except: